Quantum Coin Toss

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()

In the first two lines of the actual code, we decide if even or odd will be head or tails.

In the third line, we initiate the random number generator to give a single value that is not greater than 1,000,000.

In the fourth line, we do the actual pick from a real-time stream of quantum mechanically appearing numbers.

Putting it all together, if we get as outputeven from the first line, and heads from the second line, and 20301 from the fourth line, we then know we have tails .

To express the some properly in a function that directly answers the question between two arbitrary alternatives:

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.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Redis Fragmentation and Optimization

Banner

Elegant Python code reproduction of "most common words from a story"

Run your own high performance EBS wherever Kubernetes runs

The Passion for Developer Advocacy in the Kin Ecosystem

Modifying sprint backlog during the planned sprint

Kotlin Tutorial (Part 3) — Basic Syntax

Building A Simple Voice Assistant for Your Mac in Python

Architecture and Workflow Overview

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

Mikko

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

More from Medium

Quantum Error Correction and the Black Hole Information Paradox

NBA Big Board 2.0

From Mars to Earth