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/weighted_random_bit/Solution.qs

14lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Math;
3 open Microsoft.Quantum.Measurement;
4
5 operation WeightedRandomBit(x : Double) : Int {
6 let theta = 2.0 * ArcCos(Sqrt(x)); // (or) 2.0 * ArcSin(Sqrt(1.0 - x));
7
8 use q = Qubit();
9 Ry(theta, q);
10
11 let result = MResetZ(q);
12 return result == Zero ? 0 | 1;
13 }
14}
15