TreatmentPlant <tr************@DIESPAMMERS.iinet.net.au> wrote:

I need to generate a few thousand true random numbers using C++.

I have some code now that does alright, but when you plot the results on

a graph, you notice patterns, so the numbers are not truly random, but

pseudo-random.

This is very much not a C++ question. Use of random number generators

is independant of the host language. In any case, the obvious thing I

notice is that you're using rand(). On most systems, random()

provides a much better PRNG (pseudo-random number generator) than

rand().

Beyond that, you really need to do some reading about statistics to

understand if random() is good enough for your purposes. No matter

how random the number sequence is, you'll always find *some* patterns.

For example, if you pick enough random numbers, you will occassionally

find 4 in a row which are increasing in value. It takes a fairly deep

understanding of statistics to figure out if such patterns are

significant or not.

Even random() generates "pseudo-random" numbers. I'm not sure exactly

what you mean by "truly random", but if you want to avoid PRNGs, you

need to base your random number generator on some physical process,

such as measuring the event intervals of radioactive decay, or photon

arrival times. Many systems have an "entropy store", which attempts

to measure physical events like keystroke intervals and disk head seek

times to get better randomness.

If you're dealing cards from a deck for a game of on-line poker,

random() should be good enough. If you're building a cryptographic

system, it may not be. It's not an easy question to answer.