microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
13b05db04865cab0726abb5da17bb635b9f64fba

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

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