Created
April 29, 2012 09:49
-
-
Save benhosmer/2549087 to your computer and use it in GitHub Desktop.
A BASH script to generate 100 random numbers using the Quantum Random Number Generator, and write them to a file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # This script requires the Quantum Random library https://github.com/lmacken/quantumrandom | |
| # Use pip: pip install quantumrandom http://pypi.python.org/pypi/quantumrandom | |
| for i in {1..100}; | |
| do qrandom --int --max 1 --min 1000 >> 100-numbers.txt; | |
| done; | |
| echo "Complete!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set the number of qubits
num_qubits = 3
Initialize a quantum device
dev = qml.device("default.qubit", wires=num_qubits)
Quantum circuit to generate random numbers and calculate decimal value
@qml.qnode(dev)
def random_circuit():
for i in range(num_qubits):
qml.Hadamard(wires=i)
return [qml.expval(qml.PauliZ(wires=i)) for i in range(num_qubits)]
Execute the quantum circuit
random_numbers = random_circuit()
Convert measurement outcomes to decimal
decimal_value = sum([random_numbers[i] * 2**i for i in range(num_qubits)])
Print the random numbers and the corresponding decimal value
print("Random numbers generated by the quantum circuit:", random_numbers)
print("Decimal value:", decimal_value