Home / News / A mental random number generator

A mental random number generator

![Man thinking of random numbers](https://www.johndcook.com/think_random2.jpg)

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

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.
I recently learned about a mental RNG that Marsaglia developed.
The output is probably better than if you simply tried to make up random numbers; people are notoriously bad at doing that.
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

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

Tagged:

Leave a Reply

Your email address will not be published. Required fields are marked *