How to generate cryptographically random numbers?

I want to know how can we generate a list of different random numbers in c.?

  • I want to know how can we generate a list of different random numbers in c. is there any function in c which can automaticaaly generate a list of different random numbers . plz help me.

  • Answer:

    #include <stdio.h> #include <stdlib.h> #include <time.h> int main (int argc, char *argv[]) { /* Simple "srand()" seed: just use "time()" */ unsigned int iseed = (unsigned int)time(NULL); srand (iseed); /* Now generate 5 pseudo-random numbers */ int i; for (i=0; i<5; i++) { printf ("rand[%d]= %u\n", i, rand ()); } return 0; } This will produce five random numbers using the system clock as the seed. This ensures running back to back, the same random numbers are not generated. HTH - Good Luck, -Aaron

monal r at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

it depends on what do you mean by "different random numbers"... are you thinking about the distribution?! the std c func is rand(); you can set the seed of the random sequence with srand(number); the same seed gives the same sequence (this is property that is needed, not a proof of poor randomness) each time you call rand(), you obtain the "next" number of that sequence. rand() returns "random" (pseudorandom) intergers from 0 to RANDMAX. so if you need random num from 0.0 to 1.0, or others, you need a little bit of extra computation

Tizio 008

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.