• Please review our updated Terms and Rules here

Random Number Generators: Coding Tips & Tricks?


25k Member
Jan 11, 2007
Pacific Northwest, USA
one of my favorite random number tricks is to use the human behind the keyboard. keep a timer or simple counter running between choices on a couple menu selections and use the time between button presses/menu selections as your seed.

Don't forget the hardware RNGs--the simplest uses an avalanche (breakdown) diode to generate shot noise, which is then amplified and use to free-run a counter. One of the earliest published lists of random numbers was created this way (1955). The method is still used in some cryptographic hardware. Unlike PRGs, the sequence is not repeatable on demand.

If you need a collection of non-consecutive numbers with an even distribution, consider using an LFSR (linear feedback shift register), using either software or hardware. The bits comprising these numbers, however, are not random.

As an earlier poster has said, it depends upon your needs.