microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
8829ede154fe072649e1bb87bf1cbb81b7f96db0

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

19lines · modeblame

441fbd35Bill Ticehurst1 years ago1from pathlib import Path
0781c925Moumita1 years ago2import qsharp
3
441fbd35Bill Ticehurst1 years ago4this_dir = Path(__file__).parent
5qsharp.init(project_root=this_dir)
0781c925Moumita1 years ago6
939e2aafStefan J. Wernli1 years ago7from qsharp.code.GenerateRandomNumbers import GenerateRandomNumbers
8
0781c925Moumita1 years ago9nQubits = input("Enter the number of random bits to be generated: ")
939e2aafStefan J. Wernli1 years ago10(results, number) = GenerateRandomNumbers(int(nQubits))
0781c925Moumita1 years ago11
12count = 0
13for result in results:
14if result == qsharp.Result.One:
15count += 1
16
17print(f"Bits generated: {results}")
18print(f"Number of Ones: {count}")
19print(f"The integer representation of the generated {nQubits} bits: {number}")