473,902 Members | 4,336 Online

# True Random numbers

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.

I tried randomly seeding the seed! to see if that improved things; it
didn't.

Can anyone help?

--8<-------------------------
float l_fMin=0.0;
float l_fMax=99.999;
int newSeed;
float num;

srand((unsigned )time(NULL));

for(int i=0;i<=2000;i++ )
{
newSeed=rand();
srand((unsigned )newSeed);
num = ((float)rand() / (RAND_MAX+1)) * ((float)rand() / (RAND_MAX+1));

pfRandom[i] = (float)((num * (l_fMax - l_fMin)) + l_fMin);
}
Apr 24 '06
11 12836
In article <11************ *********@e56g2 000cwe.googlegr oups.com>,
"Old Wolf" <ol*****@inspir e.net.nz> wrote:
Roy Smith wrote:
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.

Not quite sure you have your priorities straight there :)
Any non-randomness in a poker RNG could translate into millions
of dollars of difference. Try reading rec.gambling.po ker for a day
and look at all the threads discussing RNGs.

You may be right! How about generating initial setups for a game of "Hunt
the Wumpus"?
Apr 27 '06 #11
On 26 Apr 2006 20:48:29 -0700, "Old Wolf" <ol*****@inspir e.net.nz>
wrote:

Not quite sure you have your priorities straight there :)
Any non-randomness in a poker RNG could translate into millions
of dollars of difference. Try reading rec.gambling.po ker for a day
and look at all the threads discussing RNGs.

Not really, because shuffling a deck of physical cards is by far not
random. Not all cards are equal! Same as roulette in a real casino.
Different story with internet gambling, though.

With internet poker you have to take the algorithms of the virtual
casinos into account. Try Black Jack, much easier.
Apr 28 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.