-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.qs
More file actions
34 lines (30 loc) · 872 Bytes
/
Copy pathProgram.qs
File metadata and controls
34 lines (30 loc) · 872 Bytes
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
namespace Project_QRandom {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
operation GenerateQubit() : Result {
use q = Qubit() {
H(q);
return MResetZ(q);
}
}
operation SRandomNumber(max : Int) : Int {
mutable output = 0;
repeat {
mutable bits = new Result[0];
for idxBit in 1..BitSizeI(max) {
set bits += [GenerateQubit()];
}
set output = ResultArrayAsInt(bits);
} until (output <= max);
return output;
}
@EntryPoint()
operation Number() : Int {
let max = 35;
Message($"Generate Random Number Lower Than {max}: ");
return SRandomNumber(max);
}
}