Heads or Tails? Exploring Quantum Weirdness with a Virtual Coin Flip

This article was co-authored by @jr_solon_shoshacao . Have you ever wondered how quantum computers work, or thought they were only for scientists and tech giants? What if I told you that you could experiment with quantum computing yourself, starting with something as simple as a virtual coin flip? But first... Why should I even learn this? Quantum technology is opening the door to a new era of computing — one that’s faster, smarter, and capable of solving problems that even today’s most powerful machines can’t handle. From breakthroughs in medicine and cybersecurity to advances in AI and optimization, the impact is huge. And the best part? It’s no longer out of reach. In this article, we’ll show you how to set up Qiskit, code a quantum coin flip, and introduce you to some of the basic concepts of quantum computing along the way. Here's what we'll explore: Why Quantum Computing Feels Inaccessible (and Why That’s Changing) Meet Qiskit: IBM’s Quantum Programming Framework Getting Started: Installing Qiskit Locally (or Using Colab) Coding The Quantum Coin Flip Interpreting the Quantum Coin Flip: What Superposition and Randomness Really Mean So... What Now? Why This Matters More Than You Think Wrap-Up: The Quantum World Is More Accessible Than You Think Interested In Learning More? Why Quantum Computing Feels Inaccessible (and Why That’s Changing) We’re used to computers following clear rules—ones and zeros, true or false. But quantum computing challenges that certainty, offering a new way of thinking where uncertainty isn’t a bug, but a feature. For a long time, that uncertainty made quantum computing feel out of reach. Quantum computing has been surrounded by complex math equations, abstract theories, and has a serious lack of tools for beginners. But right now, that's changing. With platforms like Qiskit, learning the basics of quantum computing is becoming more accessible, no PhD or million-dollar lab required. You can even get started with something as simple as a virtual coin flip. So if you’ve ever been curious about quantum computers but didn’t know where to start, you’re in the right place. Let’s flip the coin and see where it lands. Meet Qiskit: IBM’s Quantum Programming Framework Qiskit is an open-source quantum computing framework developed by IBM that lets you build and run quantum circuits using Python. It’s designed to make quantum programming more accessible, whether you’re a researcher or just getting started. With Qiskit, you can simulate quantum behavior, visualize results, and even run your code on real quantum computers through the IBM Quantum cloud—all from your own device. Getting Started: Installing Qiskit Locally (or Using Colab) Before we can start flipping quantum coins, we need to set up a few things. If you’d rather skip installing it locally and just try things out in your browser, feel free to jump to Step 7. 1. Install Python The latest Qiskit requires Python 3.9 or higher. To check your current Python version, open a terminal and run: python --version If your version is 3.9 or above, you’re good to go. If not, download the latest version from python.org. 2. Create a Virtual Environment This step keeps your Qiskit setup clean and separate from the rest of your Python projects. Think of it as a sandbox where your quantum code can play safely. Open your terminal and navigate to your project folder. Run: python -m venv .venv Then activate the environment: Windows (Powershell): .\.venv\Scripts\Activate.ps1 Windows (Command Prompt): .\.venv\Scripts\activate Git Bash: source .venv/scripts/activate macOS/Linux: source .venv/bin/activate You’ll know it’s working when you see (.venv) appear at the beginning of your terminal line. 3. Check for pip pip is Python’s tool for installing packages (like Qiskit). It usually comes with Python, but let’s double-check. Run pip --version. If you see a version number, you’re all set. If not, follow the official installation guide here. 4. Install Qiskit Now install the Qiskit SDK with: pip install qiskit. This is basically the Qiskit SDK that gives you core tools needed to create and simulate quantum circuits. 5. Install Qiskit Visualization Tools To see what’s going on inside your quantum circuits (trust us, it’s super cool), install the visualization extras: pip install qiskit[visualization]. 6. (Optional) Install Jupyter Notebook We’ll use Jupyter Notebook, but any Python IDE works. If you don’t already have Jupyter, install it with: pip install jupyter To launch it, simply run: jupyter notebook

Apr 24, 2025 - 12:53
 0
Heads or Tails? Exploring Quantum Weirdness with a Virtual Coin Flip

This article was co-authored by @jr_solon_shoshacao .

Have you ever wondered how quantum computers work, or thought they were only for scientists and tech giants? What if I told you that you could experiment with quantum computing yourself, starting with something as simple as a virtual coin flip?

But first...

Why should I even learn this?

Quantum technology is opening the door to a new era of computing — one that’s faster, smarter, and capable of solving problems that even today’s most powerful machines can’t handle. From breakthroughs in medicine and cybersecurity to advances in AI and optimization, the impact is huge.

And the best part?

It’s no longer out of reach.

In this article, we’ll show you how to set up Qiskit, code a quantum coin flip, and introduce you to some of the basic concepts of quantum computing along the way.

Here's what we'll explore:

  1. Why Quantum Computing Feels Inaccessible (and Why That’s Changing)
  2. Meet Qiskit: IBM’s Quantum Programming Framework
  3. Getting Started: Installing Qiskit Locally (or Using Colab)
  4. Coding The Quantum Coin Flip
  5. Interpreting the Quantum Coin Flip: What Superposition and Randomness Really Mean
  6. So... What Now? Why This Matters More Than You Think
  7. Wrap-Up: The Quantum World Is More Accessible Than You Think
  8. Interested In Learning More?

Why Quantum Computing Feels Inaccessible (and Why That’s Changing)

We’re used to computers following clear rules—ones and zeros, true or false. But quantum computing challenges that certainty, offering a new way of thinking where uncertainty isn’t a bug, but a feature.

For a long time, that uncertainty made quantum computing feel out of reach. Quantum computing has been surrounded by complex math equations, abstract theories, and has a serious lack of tools for beginners.

But right now, that's changing. With platforms like Qiskit, learning the basics of quantum computing is becoming more accessible, no PhD or million-dollar lab required. You can even get started with something as simple as a virtual coin flip.

So if you’ve ever been curious about quantum computers but didn’t know where to start, you’re in the right place. Let’s flip the coin and see where it lands.

Meet Qiskit: IBM’s Quantum Programming Framework

Qiskit is an open-source quantum computing framework developed by IBM that lets you build and run quantum circuits using Python. It’s designed to make quantum programming more accessible, whether you’re a researcher or just getting started. With Qiskit, you can simulate quantum behavior, visualize results, and even run your code on real quantum computers through the IBM Quantum cloud—all from your own device.

Getting Started: Installing Qiskit Locally (or Using Colab)

Before we can start flipping quantum coins, we need to set up a few things. If you’d rather skip installing it locally and just try things out in your browser, feel free to jump to Step 7.

1. Install Python

The latest Qiskit requires Python 3.9 or higher. To check your current Python version, open a terminal and run: python --version

If your version is 3.9 or above, you’re good to go. If not, download the latest version from python.org.

2. Create a Virtual Environment

This step keeps your Qiskit setup clean and separate from the rest of your Python projects. Think of it as a sandbox where your quantum code can play safely.

  1. Open your terminal and navigate to your project folder.
  2. Run: python -m venv .venv
  3. Then activate the environment:
  • Windows (Powershell): .\.venv\Scripts\Activate.ps1
  • Windows (Command Prompt): .\.venv\Scripts\activate
  • Git Bash: source .venv/scripts/activate
  • macOS/Linux: source .venv/bin/activate

You’ll know it’s working when you see (.venv) appear at the beginning of your terminal line.

3. Check for pip

pip is Python’s tool for installing packages (like Qiskit). It usually comes with Python, but let’s double-check. Run pip --version.

If you see a version number, you’re all set. If not, follow the official installation guide here.

4. Install Qiskit

Now install the Qiskit SDK with: pip install qiskit.

This is basically the Qiskit SDK that gives you core tools needed to create and simulate quantum circuits.

5. Install Qiskit Visualization Tools

To see what’s going on inside your quantum circuits (trust us, it’s super cool), install the visualization extras: pip install qiskit[visualization].

6. (Optional) Install Jupyter Notebook

We’ll use Jupyter Notebook, but any Python IDE works. If you don’t already have Jupyter, install it with: pip install jupyter

To launch it, simply run: jupyter notebook

That’s it! You're ready to start running quantum circuits locally with Qiskit.

7. Don’t Want to Install Anything? Try Google Colab

If you’re just curious and want to test things out without setting up your computer, no problem.

Go to Google Colab and type the following in a code cell: !pip install qiskit

With that one line of code, you’ve opened the door to hands-on quantum computing right in your own browser.

Coding the Quantum Coin Flip

Now that we’ve got the tools, let’s get to the fun part - coding our quantum coin flip!

Image description
Source: Tumblr

Add the following blocks of code to your notebook. I recommend using Jupyter Notebook, as some method calls need to be the last line in a cell to display properly.

Don’t worry if you’re not sure what every line does or if some of the terms sound unfamiliar — we’ll break it all down shortly. To help you follow along, we’ve also added comments next to the code to explain what each part does.

Cell 1: Import Libraries

This cell sets up everything we need - building the quantum circuit, simulating it, and visualizing results.

%matplotlib inline # Enable inline plotting

from qiskit import QuantumCircuit, transpile  # Import necessary Qiskit modules
from qiskit_aer import Aer # Aer is a simulator for running quantum circuits
from qiskit.visualization import * # Import visualization functions

If you ever run an error related to Aer, just run this in another cell: !pip install qiskit-aer.

Cell 2: Create the Quantum Circuit

circuit = QuantumCircuit(1, 1)  # Create a quantum circuit with 1 qubit and 1 classical bit
circuit.draw() # Draw the initial circuit

When you run this cell, this will be displayed:

Image description

The "q" represents the quantum register with 1 qubit, and "c" is the classical register with 1 bit. You might have noticed that there are no connecting lines (or wires) in the diagram. This is because no quantum gates (such as H, X, CX, or measurement) have been applied yet.

Cell 3: Add the Hadamard Gate and Measurement

circuit.h(0) # Apply a Hadamard gate to the qubit (puts it in superposition)
circuit.measure([0], [0]) # Measures q[0] and stores the result in classical bit c[0].
circuit.draw() # Draw the updated circuit

You should see something like this:

Image description

When we apply the Hadamard gate (H), it puts our qubit into a superposition, meaning it's not just in the state of heads or tails, but in a quantum blend of both at once. It sounds wild, right? It’s like the coin is spinning in the air, both heads and tails at the same time. But that’s exactly the kind of counterintuitive behavior quantum mechanics is known for.

Of course, we don’t see this superposition directly. The moment we measure (M) the qubit, the superposition collapses, and we get a single result — either heads (0) or tails (1). That outcome is then stored in a classical bit, which we can read using regular Python code.

Cell 4: Simulate the Circuit

backend = Aer.get_backend('qasm_simulator') # Use the Aer simulator to simulate the quantum circuit
job = backend.run(circuit, shots=1) # Run the circuit with 1 shot
counts = job.result().get_counts(circuit) # Get the result of the measurement
print("Result:")
if '0' in counts.keys():
    print("tail")
else:
    print("head")

This simulates the quantum circuit (from cell 2) using a Quantum Assembly (QASM) simulator, a simulator used for circuits that include measurement and probabilistic behavior, like superposition and randomness.

The shot parameter simply means how many times the circuit should be run and measured. Each time, the qubit collapses into either a 0(tail) or a 1(head). The simulator records the results, and then we print out the outcome to see whether we got heads or tails. An example output is this:

Image description

Cell 5: Run Multiple Shots

job = backend.run(circuit, shots=100) # Run the circuit 100 times to simulate multiple coin flips
counts = job.result().get_counts(circuit) # Get how many times each outcome (0 or 1) occurred
print("Result:", counts) # Print the results as a dictionary of counts

This time, we increase the number of shots to 100, meaning we run the quantum coin flip 100 times. This allows us to observe how often the outcome is 0 (tail) or 1 (head) over many runs.

Since the Hadamard gate creates a perfectly balanced superposition, we’d expect the results to be roughly 50/50. But just like flipping a real coin 100 times, small variations can still happen, and that’s part of the fun of quantum randomness.

Cell 6: Visualize the Results

plot_histogram(counts)

An example output:

Image description

As you can see, while it's not exactly a 50/50 split, the results are still close to balanced. This small variation is due to the randomness inherent in quantum measurement.

So, how is this really different from a regular coin flip? That’s what we’ll explore next, as we dig into the quantum concepts behind this strange and fascinating behavior.

Interpreting the Quantum Coin Flip: What Superposition and Randomness Really Mean

In a typical coin flip, we say the chances of getting heads or tails are 50/50. But in reality, a coin flip is deterministic—if we knew every detail about how it was tossed (like the force, angle, and air resistance), we could predict the outcome. It only seems random because it’s too complex to track.

But what about a quantum coin flip?

Instead of just landing on a random 0 (tails) or 1 (heads), the qubit enters a state called superposition. That means it's not just one or the other—it’s in a mix of both 0 and 1 at the same time, thanks to quantum mechanics. You can see this in our coding experiment, where we apply a Hadamard gate to the qubit to create the superposition.

However, once we measure the qubit (symbolized by the eye in the GIF below), the superposition collapses, and we get a single result — either 0 or 1. That’s why you only see one result, as shown in cell 4.


Source: National Institute of Standards and Technology

While most people think coin flips are perfectly random, studies show they’re actually about 0.8% more likely to land on the same side that was facing up at the start.

In contrast, quantum outcomes are truly probabilistic, and their roughly 50/50 results after many runs reflect the core principle of quantum mechanics — that outcomes are fundamentally governed by probability, not predictability.

The quantum coin flip is genuinely random at a fundamental level. This randomness isn't just noise; it's a feature, and it's what makes quantum computing so powerful for certain types of problems.

So... What Now? Why This Matters More Than You Think

At this point, you might be wondering:

Is that it? Just a fancy coin toss?

Fair question, but what you’ve just seen is only the tip of the quantum iceberg. By going further, you will encounter concepts like entanglement, where particles remain mysteriously connected no matter how far apart they are. You’ll learn about interference, the trick quantum algorithms use to boost correct answers and cancel out the wrong ones.

But does knowing these things even matter?

Absolutely.

That superposition you just experimented with? It’s the very reason quantum computers can represent multiple states at once, allowing parallel processing and faster computation for complex problems.

This quantum power could revolutionize industries like:

  • Drug Discovery: Design life-saving drugs by simulating molecules more accurately than ever before.
  • Cybersecurity: Create unbreakable encryption methods to secure the digital world.
  • Optimization: Optimize supply chains, traffic flows, and even climate models with unprecedented efficiency.
  • Finance: Modeling financial systems, detecting fraud, and optimizing portfolios with powerful probabilistic tools.
  • Artificial Intelligence: Accelerating machine learning and unlocking new ways to process and analyze massive data sets.

Superposition is just one piece of the puzzle. That little coin flip? It wasn’t just a demo—it was your first real step into the quantum world.

Wrap-Up: The Quantum World Is More Accessible Than You Think

Quantum
Source: Stephanie Ball on erp.today

Every breakthrough in technology starts with a moment where it seems impossible—too new, too strange, too complicated. Quantum computing was no different. For years, it sat at the edge of innovation, something only researchers and physicists dared to touch. But now, that edge is moving. The tools are simpler, the barriers are lower, and curiosity is all you need to begin. And here you are, flipping a quantum coin from your laptop like it’s no big deal. And that’s the point.

This little experiment, as simple as it may seem, is your first hands-on encounter with the quantum world. You didn’t just read about superposition, you coded it. You didn’t just hear about quantum randomness, you watched it unfold across 100 simulations. No lectures, no whiteboards covered in Greek symbols. Just you, a few lines of Python, and a gateway into one of the most exciting technologies of our time.

What used to be an exclusive playground for physicists is now open to anyone with curiosity and a bit of code. Qiskit makes that possible. Whether you're a student, a hobbyist, or someone who just stumbled in because "quantum coin flip" sounded cool (and it is), you're now part of this story. You’ve seen how approachable quantum computing can be. Not easy, because quantum stuff is strange, but definitely learnable, and way less scary than it used to be.

So what’s next? You could stop here and call it a win, and honestly, it is. Or maybe you go a step further. Try a two-qubit system. Run your circuit on a real quantum computer via IBM’s cloud. Or maybe, just maybe, you dive headfirst into building something only quantum computers can do. Whatever your next move, you’ve already taken the hardest step: starting. And just like that, the quantum world doesn’t feel so far away anymore.

Interested In Learning More?

If you're excited about diving deeper into quantum computing, here are some fantastic resources to help you get started:

Other Quantum Computing Frameworks