help with random number generator

May 5, 2012 at 1:56pm
guys I'm new to C++. I need a help. I mean;

srand((unsigned)time(NULL));

I don't understand this code. can anyone please explain me these codes individually ? and I dont what what the seed value is in random number generator ?
May 5, 2012 at 2:51pm
closed account (2NywAqkS)
Computers work because of logic gates, because of this they cannot produce random numbers. The way proggrammers work around this is through Pseudorandom number generator (http://en.wikipedia.org/wiki/Linear_congruential_generator). Based on a given number this will generate a seeming random number between 0 and RANDMAX. This given number is called a seed. srand will set a seed for the random numbers. (unsigned)time(NULL) just makes 'the time' a seed so that you get varied results every time you run the program. To get a random number after seeding it with srand, use
int randomNumber = rand() % 10
to generate a number between 0 and 9

Hope this helps :)
Last edited on May 5, 2012 at 2:54pm
Topic archived. No new replies allowed.