mardi 9 janvier 2018

Create two differently seeded independent RNG in C

How can I create two independent random number generators (without the necessity for being cryptographically secure) in C? One of both RNGs should offer random numbers seed using srand(time(NULL));, while the other should be initialized using a commandline parameter for creating reproducible experiments. Below example will seed the same RNG with two different values, how will this work having two different possible rand() calls?

#include <stdlib.h>
#include <time.h>

int main(int argc, char**argv)
{
    // seed first RNG
    srand(time(NULL));
    // seed second RNG
    srand(argv[1]);
    // use both RNGs in production code for 
    // different purposes ...
    return 0;
}




Aucun commentaire:

Enregistrer un commentaire