microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/random_numbers/random_bit/Solution.qs

19lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Measurement;
3 operation RandomBit() : Int {
4 // Allocate single qubit.
5 use q = Qubit();
6
7 // Convert the qubit state to |+>.
8 H(q);
9
10 // Measure the qubit and reset it to |0>.
11 let result = MResetZ(q);
12
13 // Return integer value of result.
14 if result == One {
15 return 1;
16 }
17 return 0;
18 }
19}
20