   First Random Number always the same? (VC++6)
int randomRange(int lowerBound, int upperBound){    if(lowerBound > upperBound)  { return -1; }    int range = upperBound - lowerBound + 1;    return lowerBound + int(range * rand()/(RAND_MAX + 1.0));}blabla(..){    srand(static_cast(time(0)));    cout << randomRange(2,4) << endl;}  or justsrand((unsigned)time( NULL ));for (int i=0; i < 2; i++){cout << ((rand()*3)/RAND_MAX) + 2 << endl;}  the first number is always the same -> what''s wrong? 
  put this at start of programsrand(time(NULL));random number generator is NOT random but an apparent looking mathematical formulasrand "seeds" the generator producing a different sequence and with the value produced by time(NULL) which gets the systems current time which is usually a different number everytime you run it because the time on the system is continously incrementing.BUT if someone would happen to run the program at the exact same time instant on more than one occasion (i.e run it then reset system time and by some miricle do it at the same instant again) then it would again produce the same resultssince that is highly unlikely....you can be pretty safe with the srand(time(NULL));  solution "A soldier is a part of the 1% of the population that keeps the other 99% free"  - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA ;  it never returned 0 and I am aware of srandboth errors are not my problem! ;  try this thensrand(time(NULL));int range = 100;  // just some number you want the range to be// print 5 random numbers(for int i = 0; i < 5; i++){   cout << (rand()%range) << endl;}    "A soldier is a part of the 1% of the population that keeps the other 99% free"  - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA ;  trying to rephrase:when looped (eg. 10 times) the first value will always be the same (not 0 and not the lower bound!!!), while the others are different each (run)timeEDIT: I'll try above - you guys ARE quick =)   [edited by - MarsFreak on February 3, 2004 10:03:11 AM];quote:Original post by ncsu121978   ...   cout << (rand()%range) << endl;...   quote:The Evils of rand()  ...the low bits returned by some implementations of rand() are not very random, which means that you get very little randomness even when you use a modulus other than 2.Mersenne Twister[Edit: Quotes]   [edited by - Oluseyi on February 3, 2004 2:05:49 PM];(for int i = 0; i < 100; i++){   srand(time(NULL));   cout << rand() << endl;}  If you where doing something like that then it won''t work because the value of time() won''t have changed each time it goes round the loop (assuming you have a computer built before the 1960s ). If you seed the random number generator with the same number each time, the subsequent random numbers generated will always be the same. ;  what he is saying is.......for the following psudo code:srand(200);// print 5 random numberscout << "first set" << endl;(for int i = 0; i < 5; i++){   cout << (rand()%range) << endl;}   cout << "second set" << endl;srand(400);// print 5 random numbers(for int i = 0; i < 5; i++){   cout << (rand()%range) << endl;}   cout << "thirdset" << endl;srand(591);// print 5 random numbers(for int i = 0; i < 5; i++){   cout << (rand()%range) << endl;}he would get output like:first set512312344321433421344324562second set5354913492779129231981564981third set51951987265491959652149594912Could just be a crappy implemntation of the rand() function.  What compiler are you using?possible solutions could be to find an external psudorandom number generator or just throw away the first result of rand() when you seed it with srand().