diff --git a/quantum/quantum_random.py b/quantum/quantum_random.py new file mode 100644 index 000000000000..01c8faa12ac0 --- /dev/null +++ b/quantum/quantum_random.py @@ -0,0 +1,30 @@ +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) diff --git a/requirements.txt b/requirements.txt index b14a3eb0157c..25d2b4ef93d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ numpy opencv-python pandas pillow +projectq qiskit requests scikit-fuzzy