I just did a basic search for "C++ Random Number" in google and got this srand()
The pseudo random number generator produces a sequence of numbers that
gives the appearance of being random, when in fact the sequence will
eventually repeat and is predictable.
We can seed the generator with the srand() function. This will start
the generator from a point in the sequence that is dependent on the
value we pass as an argument. If we seed the generator once with a
variable value, for instance the system time, before our first call of
rand() we can generate numbers that are random enough for simple use
(though not for serious statistical purposes).
In our earlier example the program would have generated the same number
each time we ran it because the generator would have been seeded with
the same default value each time. The following code will seed the
generator with the system time then output a single random number,
which should be different each time we run the program. #include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
srand((unsigned)time(0));
int random_integer = rand();
cout << random_integer << endl;
}
![]() |
Seppukuties is like LBP Lite, on crack. Play it already!Currently wrapped up in: Half Life, Portal, and User Created Source Mods
|








