File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ ##################################################################################################
You can’t perform that action at this time.
0 commit comments