A mental random number generator

Man thinking of random numbers

George Marsaglia was a big name in random number generation. I’ve referred to his work multiple times here, most recently in this article from March on randomly generating points on a sphere. He is best remembered for his DIEHARD battery of tests for RNG quality. See, for example, this post.

I recently learned about a mental RNG that Marsaglia developed. It’s not great, but it’s pretty good for something that’s easy to mentally compute. The output is probably better than if you simply tried to make up random numbers; people are notoriously bad at doing that. Hillel Wayne explores Marsaglia’s method in detail here.

Here’s a summary the generator in Python.

state = 42 # Set the seed to any two digit number

def random_digit():
    tens = lambda n: n // 10
    ones = lambda n: n % 10
    global state
    state = tens(state) + 6*ones(state)
    return ones(state)

Related posts

3 thoughts on “A mental random number generator

  1. I believe the last line to be incorrect: the result of the PRNG is a two dogit number, so it should be `return state % 100`, otherwise you’ll get a single digit.

  2. If you have a friend nearby you can also both pick a “random” number in the desired range and then add them together modulo the max value. Me and my friends used to use this when playing D&D on the road without dice.

Comments are closed.