The sources of the demo programs are fairly complex. A very simple problem is given here to show the general techniques when programming with libquantum. This program implements a quantum random number generator, that returns either 0 or 1 with equal probability.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <quantum.h>
int main ()
{
quantum_reg reg;
int result;
srand(time(0));
reg = quantum_new_qureg(0, 1);
quantum_hadamard(0, ®);
result = quantum_bmeasure(0, ®);
printf("The Quantum RNG returned %i!\n", result);
return 0;
}
|