-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.qs
36 lines (30 loc) · 993 Bytes
/
Program.qs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace SolacedQuantum {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
operation GenerateRandomBit() : Result {
use q = Qubit();
H(q);
return M(q);
}
operation SampleRandomNumberInRange(min : Int, max : Int) : Int {
mutable output = min - 1;
repeat {
mutable bits = [];
for idxBit in 1..BitSizeI(max) {
set bits += [GenerateRandomBit()];
}
set output = ResultArrayAsInt(bits);
} until (output >= min and output <= max);
return output;
}
@EntryPoint()
operation SampleRandomNumber() : Int {
let min = 100;
let max = 10000;
Message($"Sampling a random number between {min} and {max}: ");
return SampleRandomNumberInRange(min, max);
}
}