views:

193

answers:

4

Are there are any pseudo-random number generators that are easy enough to do with mental arithmetic, or mental arithmetic plus counting on your fingers. Obviously this limits to fairly simple math - it needs to be something someone of average mathematical ability can do, or maybe average ability for a programmer, not a math prodigy.

The simplest I have found is the Middle square method, but not only is it known to be a poor source of randomness, it still looks too complex to do without pencil and paper.

If the only way to do this is by limiting the range, like maybe it only can output 8 bit numbers, that is fine. I suspect one of the standard PRNG algorithms would be simple enough in an 8 bit version, but I don't know enough to simplify any of them from the 32 bit version to an 8 bit version. (All the ones I looked at depend on specially picked seed numbers that are different depending how many bits you are working with, and usually only 32 and 64 bit examples are given.)

+1  A: 

In your head you can do "semantic" random number generation :-)

Like taking random word, and calculating some metric out of it, repeat until you'll get number with reasonable length.

For example, word "exercise" might get converted to 10100101b (you can see my conversion idea here).

BarsMonster
+3  A: 

A linear feedback shift register is pretty simple, as long as you're comfortable with thinking in binary (or maybe hex, since it's easy to map between the two).

A more complex one is Xorshift, but if you know your bitwise operations, it should be quite possible to work with as well.

Michael Madsen
+1  A: 

Pseudo-random: alt text

Margus
So you're saying "think of 9"?
GregS
No, whatever you do, do not think of 9.
Hans
I considered pre-emptively linking that one and the xkcd comic in my question.... guess I should have
LeBleu
No, whatever you do, do not think of the number between seven and nine.
Jon Purdy
+1  A: 

How about Blum Blum Shub, but with prime numbers too small for secure use? Used securely it's slow, but it involves operations that we're used to dealing with, so you might be able to get to a manageable speed without too much practice, maybe with M = 437 or moderately bigger.

I doubt whether anything I could do in my head will be secure, anyway. I just can't remember big enough numbers to work without mistakes on a reasonably-sized state.

You can easily do a 10 bit LFSR on your fingers, if you have decent tendons ;-)

Not a direct answer, but depending why you're asking you might be interested in Solitaire, which generates a keystream (i.e. a pseudo-random sequence) using a deck of cards. Can't be done in your head, but doesn't require pencil and paper.

Steve Jessop
I don't think Blum Blum Shub is random enough with small divisors... M = 437 gives a period of 31 or less. Also the first few numbers are always squares of the seed unless you use a large seed.
LeBleu
@LeBleu: fair enough - obviously I don't know how many numbers you need. As I say, I don't think I personally am good enough at mental arithmetic to evaluate a good PRNG, so you need either to be better than me, or to decide how bad an RNG you're willing to accept ;-)
Steve Jessop