Re: Truly random?
- From: gordon@xxxxxxxxxxxxxxxxx (Gordon Burditt)
- Date: Tue, 06 Dec 2005 16:55:58 -0000
If, as your subject line suggests, you want truly random numbers,
forget a PRNG like rand() or random(). The PR part stands for
PSEUDO-RANDOM. Computers aren't very good at generating truly
random numbers unless they are broken or they have specific hardware
for the purpose. Some attempts at truly random number generation
time keystrokes, or listen to thermal noise or radioactive decay,
or time events from outside the computer (like network traffic).
If you need truly random numbers for cryptography, a PRNG won't
do. The difference can get you killed.
>Well, I'm developing a Tetris game in SDL, but when it comes to
>deciding the next block, I'm stuck. It's random, but when I try
>something like seeding the randomizer with the time, it won't update as
>fast as one block can fall, and the next to be determined. Generating
Don't seed the PSEUDO random number generator more than once. Since
the time() call gives a time granularity of seconds on most (POSIX)
systems, and presumably blocks update faster than that, you'll get
sucky non-random numbers.
>different numbers in one spur can work, but people can play Tetris for
>hours (or even days), and so you can't predict how long. You could
>constantly be making more with the same system as making, say 5 random
>numbers out of a seed, but that would prove system intensive if the
>game already uses a lot of memory (not that Tetris does, but I'm sure
>there's a better way).
Seed once. Period. If calling rand() or random() alone slows down
the display too much, perhaps you need a faster CPU. But I doubt it.
All the graphics probably takes a lot more work than just generating
a pseudo-random number.
Gordon L. Burditt
.
- Follow-Ups:
- Re: Truly random?
- From: Randy Howard
- Re: Truly random?
- From: Alvin
- Re: Truly random?
- References:
- Truly random?
- From: Alvin
- Truly random?
- Prev by Date: Re: Parsing Microsoft Debug Symbol Tables...
- Next by Date: Re: Truly random?
- Previous by thread: Re: Truly random?
- Next by thread: Re: Truly random?
- Index(es):
Relevant Pages
|