samedi 2 avril 2016

How to supply seed to ISAAC random number generator

I have the following code to generate a random number using ISAAC:

int main()
{
    /* Initialize the structure to 0 */
    randctx ctx;
    ctx.randa = ctx.randb = ctx.randc = (ub4)0;

    /* Initialize the seed */
    for (ub4 i=0; i<256; ++i) {
        ctx.randrsl[i] = i;
    }

    /* Initialize the random numbers from the seed */
    randinit(&ctx, TRUE);

    printf("%.8lx\n", rand(&ctx));
}

I got the above code from How to use ISAAC in C

I also have a code to read from /dev/random to get the seed:

int myFile = open("/dev/random", O_RDONLY);            
uint32_t rand;            
uint32_t randomNum = read(myFile, &rand, sizeof(rand)) ;
printf(" %u \n", rand);
close(myFile);

How do I supply the seed i.e rand to ISAAC?

Thanks




Aucun commentaire:

Enregistrer un commentaire