microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/random_numbers/random_two_bits/solution.qs

23lines · modecode

1namespace Kata {
2 operation RandomTwoBits() : Int {
3 return 2 * RandomBit() + RandomBit();
4 }
5
6 operation RandomBit() : Int {
7 // Allocate single qubit.
8 use q = Qubit();
9
10 // Set qubit in superposition state.
11 H(q);
12
13 // Measuring the qubit and reset.
14 let result = M(q);
15 Reset(q);
16
17 // Return integer value of result.
18 if result == One {
19 return 1;
20 }
21 return 0;
22 }
23}
24