mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
74325d079c
* Rename quantum_random.py to quantum_random.py.DISABLED.txt #7682 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
31 lines
726 B
Plaintext
31 lines
726 B
Plaintext
import doctest
|
|
|
|
import projectq
|
|
from projectq.ops import H, Measure
|
|
|
|
|
|
def get_random_number(quantum_engine: projectq.cengines._main.MainEngine) -> int:
|
|
"""
|
|
>>> isinstance(get_random_number(projectq.MainEngine()), int)
|
|
True
|
|
"""
|
|
qubit = quantum_engine.allocate_qubit()
|
|
H | qubit
|
|
Measure | qubit
|
|
return int(qubit)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
doctest.testmod()
|
|
|
|
# initialises a new quantum backend
|
|
quantum_engine = projectq.MainEngine()
|
|
|
|
# Generate a list of 10 random numbers
|
|
random_numbers_list = [get_random_number(quantum_engine) for _ in range(10)]
|
|
|
|
# Flushes the quantum engine from memory
|
|
quantum_engine.flush()
|
|
|
|
print("Random numbers", random_numbers_list)
|