Generate REAL Random Numbers
//If you havent yet realized it the //function 'rand()' will not produce //an actual random number because it //uses the same seed every time, the //way to fix this is to use time as //a seed for the rand function. If //this helps, rate it please.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
//Real Random Numbers
#include <iostream.h> //for the output
#include <stdlib.h> //for 'rand', 'srand'
#include <time.h> //for 'time'
int main()
{
//use time as seed for 'rand'
srand(time(0));
//create an actually random number
int a=rand();
cout<<a<<endl;
system('pause');
return 0;
}
//if you compile and run this program
//you will see that every time you
//run it there will be a new, random
//number. if you want a number in a
//given range(lets say 0-8) replace
//the call 'rand();' with 'rand()%9'
//(notice we use 9, not 8.
//P.S. try running the same program
//I used without setting srand to time
// if you run it several times you will
//notice your output is the same every
//time!!!
Original Comments (3)
Recovered from Wayback Machine