# Mentally generating a (pseudo)random {0,1}-sequence with uniform distribution

I want to learn of good ways by which to generate $$\{0,1 \}$$-sequences in my head which are (pseudo)random with uniform distribution, so that I may simulate flipping a fair two-sided, standard coin. I want to do this because sometimes, I need to pick an option randomly, but I have no equipment (such as a coin or a random number generator) handy - and I am scared of having cognitive biases creep in.

The trick/constraints in this challenge include(s):

1. the fact that I am not an exceptionally skilled mental calculator and I may need to generate these numbers under pressure or quickly;
2. I want the sequence (if it is pseudorandom) to have a fairly large period so that I can generate values many times in the same situation (say, in order to make several consecutive decisions over the course of a few seconds or minutes) without falling into an apparent pattern. I may add other constraints too. But the basic idea is that the method needs to be robust and versatile, but also reasonable in human situations.

And, of course, it has to be free of cognitive biases or other failings, except for calculation accuracy and possibly choosing the initial values.

Bonus points if it generalizes easily to $$\{0, 1, \ldots, n \}$$-sequences for small $$n$$, such that the method is still easy (etc.) to use

Thank you very much

• Although the goal is to be mental and to not rely on outside equipment, here is a relatively versatile method using external, but not specialized and pretty much ubiquitous, equipment: Check the time or temperature or something and use that value mod n. The downside is that it does not update very quickly, meaning that it is pretty much single-usage-only. – user173897 Oct 23 '17 at 5:44
• math.stackexchange.com/q/2094304/75861 coincidentally there is a related question that has been asked many months ago, though their aim was to mentally flip a coin. I think some people answered with mental ways to do so – Triatticus Oct 23 '17 at 6:13
• Unless you use some mathematical tools in your head, you're unlikely to succeed. Psychologists have asked subjects to attempt to generate random binary sequences and found they could make a computer program that would analyze subjects' choices and proceed to predict their future choices with far more than 50% accuracy. Common biases are the reluctance to choose a sub-sequence of 5 or more consecutive equal bits or a sub-sequence such as 00110011. – DanielWainfleet Oct 23 '17 at 13:57
• Well, I want to use some sort of mathematical tool or process for precisely this reason. I just want to be able to do so in my head, on the fly, quickly (rather than by using a computer). – user173897 Oct 25 '17 at 2:07
• You could try thinking of a (fairly long) word that occurs to you at the moment and then seeing if it has an odd or even number of letters. – Jair Taylor Jul 13 '18 at 3:13

When I was young I memorized the first $$100$$ or so digits of $$\pi$$. I did it for a fun challenge at the time, and for many years (decades?), I did not encounter any 'useful' application of this.

However, as my career has moved away from physics/engineering and more towards statistics, I have found that this knowledge is extremely useful as a source of unbiased random sampling.

For example, given that $$\pi = 3.1415926535897932384626433832795028841971693993751058209749\ldots$$

if I need to find a random sample of coin flips ($$0$$ or $$1$$), I consider the successive digits (after the decimal point) of $$\pi$$ modulo $$2$$. That is, if the digit is even, the outcome is $$0$$, and if it is odd, the outcome is 1. Thus, in basic results is $$\{1,0,1,1,1,0,0,1,1,1,0,1,1,1,1,0,1,0,\ldots\}$$ One can also set a different ('random seed') by skipping the first $$x$$ digits.

It should be obvious that this technique works for sampling when $$2$$, $$5$$, or $$10$$ options are required. However, what is awesome is that with only a minor modification it can works just as easily if $$3,4,6,7,8$$, or $$9$$ options are required.

For example, if you need to model a roll of a die where $$6$$ options are required, go through the digits one at a time, and if the digits is $$0,1,2,3,4$$, or $$5$$ than 'accept' that as the outcome and if it is $$6$$ or higher than 'reject' / skip that digit. This method of sampling is called rejection sampling.

Thus the sampling would be $$\{1,4,1,5,x,2,x,5,3,5,x,x,x,x,3,2,3...\} \rightarrow \{1,4,1,5,2,5,3,5,3,2,3\ldots\}$$

Finally, whenever, I need to fill up an Excel document with random $$2$$ digits numbers, I simply select the digits of $$\pi$$ two at a time.

• An issue for me is that I am not super good at memorization, but I can remember processes. However, this is a pretty good and versatile solution, for anyone with the headspace for it. – user173897 Mar 28 '20 at 23:10