Re: Truly random?



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
.



Relevant Pages

  • Re: random lottery draw funciton
    ... from approximately 18,000 shares. ... I believe rand() uses your operating system's default randsystem call, ... the quality of the pseudo-random numbers depends on your system. ... http://www.andyhsoftware.co.uk/space:: disk and FTP usage analysis tool ...
    (comp.lang.php)
  • Re: How to generate random numbers in C
    ... Computers do not generate truly random numbers without hardware support. ... You may want pseudo-random numbers. ... process ID (but NOT in applications where real random numbers are needed, ... the return type of rand() ...
    (comp.lang.c)
  • Re: Way for computing random primes in standard C.
    ... number which is also pseudo-random? ... probabilities for all the primes that are at most 32 bits. ... Does it mean that further calls to rand() will return numbers with a new ... how is it different to calling srand() with a ...
    (comp.lang.c)
  • Re: Why will this not generate a random number!?
    ... >education is mainly based on object oriented design theory where Java ... I cannot for the life of me generate a random number. ... rand() does not generate random numbers. ... How do you know the result you got is NOT pseudo-random? ...
    (comp.lang.c)
  • Re: generate 2 random numbers in rapid sequence
    ... People who work with computers often talk about their system's "random ... Given knowledge of the algorithm used to create the ... pseudo-random numbers, and pseudo-random sequences of such numbers. ...
    (comp.lang.php)