Quantum Coin Toss

An easy-to-perform quantum mechanics-based alternative to tossing a coin

import chances
import
random
# use pseudo randomness to pick either even or odd
random.choice(['even', 'odd'])
# use pseudo randomness to pick either head or tail
random.choice(['heads', 'tails'])
# set the `max` and `n` values for the random generator
rand = chances.Randomizer(1000000, 1)
# use quantum mechanical randomness to pick a number
rand.quantum()
def quantum_coin_toss(a, b):

'''Quantum coin tosser
a | str or int or list or dict | any value or set of values
b | str or int or list or dict | any value or set of values

'''

import chances
import random

# use pseudo randomness to pick either even or odd
even_or_odd = random.choice(['even', 'odd'])

# use pseudo randomness to pick either head or tail
a_or_b = random.choice([a, b])

# set the `max` and `n` values for the random generator
rand = chances.Randomizer(1000000, 1)

# use quantum mechanical randomness to pick a number
quantum_random_number = rand.quantum()[0]

# handle the case where quantum random number is even
if quantum_random_number % 2 == 0:

if even_or_odd == 'even' and a_or_b == a:
return a

elif even_or_odd == 'even' and a_or_b == b:
return b

elif even_or_odd == 'odd' and a_or_b == a:
return b

elif even_or_odd == 'odd' and a_or_b == b:
return a

if quantum_random_number % 2 != 0:

if even_or_odd == 'even' and a_or_b == a:
return b

elif even_or_odd == 'even' and a_or_b == b:
return a

elif even_or_odd == 'odd' and a_or_b == a:
return a

elif even_or_odd == 'odd' and a_or_b == b:
return b

--

--

Worked with machine intelligence for 15 years, and built the interwebs for 25. Nothing here is my own.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mikko

Worked with machine intelligence for 15 years, and built the interwebs for 25. Nothing here is my own.