Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Dancing with Qubits

You're reading from   Dancing with Qubits How quantum computing works and how it can change the world

Arrow left icon
Product type Paperback
Published in Nov 2019
Publisher Packt
ISBN-13 9781838827366
Length 516 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Robert S. Sutor Robert S. Sutor
Author Profile Icon Robert S. Sutor
Robert S. Sutor
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface
1 Why Quantum Computing? FREE CHAPTER 2 They’re Not Old, They’re Classics 3 More Numbers than You Can Imagine 4 Planes and Circles and Spheres, Oh My 5 Dimensions 6 What Do You Mean ‘‘Probably’’? 7 One Qubit 8 Two Qubits, Three 9 Wiring Up the Circuits 10 From Circuits to Algorithms 11 Getting Physical 12 Questions about the Future Afterword
Other Books You May Enjoy Appendices

6.5 Randomness

Many programming languages have functions that return pseudo-random numbers. The prefix ‘‘pseudo’’ is there because they are not truly random numbers but nevertheless do well on statistical measurements of how well-distributed the results are.

Given four possible events E0, E1, E2, and E3 with associated probabilities p0, p1, p2, and p3, how might we use random numbers to simulate these events happening?

Suppose

display math
The probabilities add up to 1.0, as expected. In Python 3, the random() function returns a random real number r such that 0.0 ≤ r < 1.0. Based on the value of r we get, we determine that one of the E0, E1, E2, and E3 events occurred.

If you are not using Python, use whatever similar function is available in your programming language and environment.

The general scheme is to run the following steps in order:

  • r < p0 then we have observed E0 and we stop. In the example...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime