Skip to content

Commit 4c5ad59

Browse files
author
Axel Dahlberg
authored
Merge pull request #20 from apassenger/master
Create quantum_number_generation.py
2 parents b70c474 + e3725c9 commit 4c5ad59

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from cqc.pythonLib import CQCConnection, qubit
2+
3+
#####################################################################################################
4+
#In this example, we produce fresh coin/random number with using quantum logical gates.
5+
# While creating quantum random generator, steps of coin analogy was used.For this
6+
# 1) a new qubit was produced and this stpe similar to fishing coin
7+
# 2) applied hadamard gate, this step can be equal that tossing a coin in air
8+
# 3)Finally measured qubit and this is like that we can learn now the coin's result like head or tail
9+
10+
11+
def main():
12+
13+
# Initialize the connection
14+
with CQCConnection("Alice") as Alice: # Here 1)we connect a node (ALice)
15+
q = qubit(Alice) # 2)produced a fresh qubit
16+
q.H() # 3)applied Hadamard gate
17+
coin = q.measure() # 4)mesaured the qubit and the result printed
18+
to_print = "{}".format(coin)
19+
print("| " + to_print + " |")
20+
return coin
21+
22+
23+
if __name__ == '__main__':
24+
coin_list = [] # here we defined an empty list for saving our generated numbers/coins
25+
for i in range(10): # for producing 10random numbers/coin used for loop
26+
coin_list.append(main()) # generated coins/number added in the list
27+
print('Quantum Coin', coin_list) # printed on the secreen
28+
29+
##################################################################################################

0 commit comments

Comments
 (0)