microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0ffa03cf0743f955072054af5eb5ce6f1cf69663

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/python_interop/generating_n_random_bits/RunGenerateRandom.py

21lines · modeblame

441fbd35Bill Ticehurst1 years ago1from pathlib import Path
21ea7aa6João Boechat1 months ago2from qdk import qsharp
0781c925Moumita1 years ago3
441fbd35Bill Ticehurst1 years ago4this_dir = Path(__file__).parent
5qsharp.init(project_root=this_dir)
0781c925Moumita1 years ago6
21ea7aa6João Boechat1 months ago7from qdk import code
8
9GenerateRandomNumbers = code.GenerateRandomNumbers.GenerateRandomNumbers
939e2aafStefan J. Wernli1 years ago10
0781c925Moumita1 years ago11nQubits = input("Enter the number of random bits to be generated: ")
939e2aafStefan J. Wernli1 years ago12(results, number) = GenerateRandomNumbers(int(nQubits))
0781c925Moumita1 years ago13
14count = 0
15for result in results:
16if result == qsharp.Result.One:
17count += 1
18
19print(f"Bits generated: {results}")
20print(f"Number of Ones: {count}")
21print(f"The integer representation of the generated {nQubits} bits: {number}")