On Wed, 29 Dec 2004 22:19:55 +0000, Keith Thompson wrote:
....
random() is not a standard C function. There is a POSIX function
called random(); your system should have documentation for it.
"man random" if you're on a Unix-like system.
My Linux man page says that it is a BSD function, AFAIK it isn't POSIX. It
apparently has a related seeding function called srandom(). The standard C
library (which of course is also available to C++ programs) provides
rand() and srand(). That's a good starting point. Don't try to mix the two
different sets of functions.
To the OP: these are examples of pseudo-random number generators. The
numbers are generated algorithmically, and the algorithms used are
designed to generate sequences that *appear* random and which fare well
for statistical tests for randomness (at least the better algorithms do).
However they aren't random in the true sense, because as you've seen the
sequences are reproducible. If you start in a particular state you will
always end up with the same sequence of numbers. This is why it is
important to "seed" the pseudo-random number generator if you want
different sequences each time.
The C standard function for generating random numbers is called rand().
It should also be documented on your system, and section 13 of the C
FAQ, <
http://www.eskimo.com/~scs/C-faq/top.html>, has some good
information. (Many implementations of rand() aren't very good; using a
non-standard function like random() might be a good idea.)
Alternatively include code for the RNG in your program. Good
implementations are written in standard C (or C++ for our fellow readers)
and using such code will not tie your program to a particular system.
Lawrence