A random number generator
Brief description of the program
The program creates a qubit (initially in maximally mixed state) which is immediately measured and the result is returned to the caller. This gives the result 0 or 1 with 50/50 probability.
Detailed description of the program
A random number generator consists of only one method from which the program is run. The program proceeds as follows:
- On line 1, a qbit variable q is declared.
- On line 2, a new qubit is allocated and q is assigned this qubit.
- On line 3, this qubit is measured in standard basis and the measured value is returned as the program result.
The program
| |
| |
| int main() { |
1 | qbit q; |
2 | q = new qbit(); |
3 | return measure(StdBasis,q); |
| } |
Download source code