microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-wasm-logging-issue

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 · modecode

1from pathlib import Path
2import qsharp
3
4this_dir = Path(__file__).parent
5qsharp.init(project_root=this_dir)
6
7from qsharp.code.GenerateRandomNumbers import GenerateRandomNumbers
8
9nQubits = input("Enter the number of random bits to be generated: ")
10(results, number) = GenerateRandomNumbers(int(nQubits))
11
12count = 0
13for result in results:
14 if result == qsharp.Result.One:
15 count += 1
16
17print(f"Bits generated: {results}")
18print(f"Number of Ones: {count}")
19print(f"The integer representation of the generated {nQubits} bits: {number}")
20