7

I'm a poker player, and often at the poker I table I want to be able to randomize to make a decision (call 1/2 of the time, raise 1/3 the time, etc). I can't flip a coin or pull out my phone at the table, so I'd like an easy way of generating that randomness inside of my head.

Requirements:

  • I'd be happy with an algorithm giving me a random bit (so random number between 1 and 2), since usually my randomization is essentially a coin flip. But I'm also interested in ways to generate a random integer between 1 and N (so I can do more complex randomization on the fly, like call 1/3 of the time).
  • I'm not very good at following complex instructions in my head, so a simpler procedure is better. Ie: I'm fine doing small additions/modulos, but the smaller the numbers and the fewer the operations, the better.
  1. It doesn't need to be truly random. Just "good enough" for a heuristic. PRNGs are fine, but it has to be simple enough for me to calculate in my head.

I'm sure there are lots of fun and clever approaches to this problem that I have not considered. Excited to hear what people can come up with!

Note: I saw this thread which asks a similar question: How to mentally flip a coin?. However, I'd like something more repeatable (a lot of these really only allow a finite amount of asks before you start to memorize the answers), as well as something that generalizes past a single bit.

weissguy
  • 422
  • 4
    I recall reading a book on poker where the advice was to decide what probability you want to assign to which outcome, and then look at your (mechanical) watch. The second hand is the random number generated. It's not super random, but if you wanted to call, say, 20% of the time, 20% of 60 is 12, so you'd call if the second hand was between 1 and 12 seconds. – A. Thomas Yerger Aug 17 '24 at 00:06
  • You have two hole cards: if the first is ranked above the second including suits, call Heads, if the second before the first call Tails. For finer precision, perhaps remember the cards from the previous hand and rank the permutations. – Henry Aug 17 '24 at 00:08
  • Nice answer! But I don't wear a watch. – weissguy Aug 17 '24 at 00:08
  • @Henry I like that answer for generating a single bit. I suppose I could repeat the process by shuffling my cards to get more bits? – weissguy Aug 17 '24 at 00:09
  • Yes - if you can do random shuffling on two cards. It may be a tell that you are randomising, so you would need to do it even when not randomising. Or shuffle some chips of varying colours. – Henry Aug 17 '24 at 00:11

2 Answers2

1

If you're capable of multiplying and adding two-digit numbers in your head, then you can use the Linear Congruential Generator with a modulus of 100.

The hard part is choosing the multiplier ($a$) and increment ($c$) to get good (for the constraints) output. At minimum, you should have:

  • $a \in \{1, 21, 41, 61, 81\}$
  • $\gcd(c, 100) = 1$. That is, $c$ is an odd number that is not a multiple of $5$.

This will ensure that your generator has a full cycle of 100 possible outputs.


Now, let's consider how to optimize coin flips. Assign random number values 00-49 as "heads", and 50-99 as "tails". Within each 100-flip cycle, there will be exactly 50 of each.

def random_sequence(multiplier, increment, modulus, seed, count):
    result = []
    for i in range(count):
        seed = (multiplier * seed + increment) % modulus
        result.append(seed)
    return result

def flip_coins(multiplier, increment, modulus, seed, count): return ''.join(('H' if value * 2 < modulus else 'T') for value in random_sequence(multiplier, increment, modulus, seed, count))

Here is an example sequence of 100 coin flips:

>>> flip_coins(41, 17, 100, 0, 100)
'HHTHTHTTHTTTTHTTTHHHTTHTHHHHTHHHHTTHHTHTTTTHTTTTHTTTHTHTHHTHHHHTHHHTTTHHTHTTTTHTTTTHHTTHTHHHHTHHHHTH'

And here is a bad example:

>>> flip_coins(1, 1, 100, 0, 100)
'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTH'

So it's not enough to balance the number of Hs and Ts. We also need to balance sequences of H's and T's.

If we require every 100-flip sequence to contain equal numbers of HH, HT, TH, and TT substrings, we reduce the number of RNG parameter combinations from 200 to 96.

By applying similar rules to sequences of 3 and 4 consecutive coin flips (requiring the distribution to be as uniform as possible, if not completely uniform), we reduce the number of combinations to 8:

$$(a, c) \in \{(21, 27), (21, 43), (21, 77), (21, 93), (81, 13), (81, 17), (81, 63), (81, 67)\}$$

Dan
  • 18,262
0

Method 1: Use a LCG $$X_{n+1}=(a\cdot X_n+c)\mod{m}$$ For an easy algorithm to use, you want small numbers, only 1 digit multiplications or additions, and a simple modulus

e.g. pick a number from 0 to 9 (let's say 1) let the rule be $$X\leftarrow(7 \cdot X+3)\mod{10}$$

how to use it: for a coin toss: if new X less than 5, choose heads, otherwise choose tails for 1 to N: mod the new number with N, then add 1 (say if X is 8 and N is 3, choose $8 \mod{3}+1 = 3$)

Method 2: If you don't want to do arithmetic, then you can use a predetermined sequence of numbers, like letting a string of digits of pi be values of X, same method of usage as Method 1.

Method 3: You could keep an internal counter with modulo, and update that number each time you make a decision (like multiply or add a random number of choice)

Note: any method that uses a fixed recurrence eventually enters a cycle, but for randomisation of only a few rounds in let's say poker, this is not a problem. Also, the more operations you add, the more "random" the result will be, but if it's too complex you might lose track, and not be worth having the randomiser.

Wafflefly21
  • 111
  • 8