samedi 4 novembre 2017

Python - randomint() should be equal to C - rand()

I have the following C - Programm:

#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[]){
    srand(time(NULL));
    printf("%d", rand());
}

And this python script:

import random
import time
random.seed(int(time.time()))
print (random.randint(0, 2147483647))

RAND_MAX in the C-program is defined as 2147483647. If I start both programs in the same second, they should print the same "random"-number but this is not so?

Any ideas why? Are there different methods implemented to get a pseudo-random number? The seed is definitely the same.




Aucun commentaire:

Enregistrer un commentaire