Random numbers

An interesting subject. Suitable for fun applications and subject to many technical considerations.

Generators

I've used several pseudo-random number generators. Linear congruenntial is the best: random, simple and fast. Greg developed this version many years ago and did exhaustive testing.

I've generated random dots on the screen and displayed histograms without seeing any patterns.

*+

This version of multiply and add is unique to this application. Seed is on the stack and the low-order of the product is replaces it. The high-order is returned as random

Uniform distribution

These decimal numbers have good properties: This generates 18 random bits. Any number can be used as a seed to start generating successive random numbers, including 0.

These pseudo-random numbers are said to have a period of only 65536. So avoid cycles with power-of-2 repetitions.

Typically you would mask fewer than 18 bits. For display using run-length video: ran 1fff and.

If you want a range that's not a power of 2:

I'm not persuaded the statistics are as good as with a power of 2, but that's the best I know to do.

Normal distribution

Summing 4 uniform numbers yields a normally distributed number. It's a severe test of randomness. I saw it develop on a 256-point histogram, summing 64-bit numbers. Magical.

The range is 4 times the uniform range with the peak centered. The range looks to be 3 sigma.

*.

17-bit fractional multiply, discarding multiplicand