Quantum Computing Simulation and Visualization  
010000101110011010100111101101101110100110111111000010101000100110101001101110101101100010100111100000111111010010100001101000101011111111100010101100111111100000101011011110011010101101111111

Simulating Measurements

One Qubit
// complex magnitude squared
//
double abs2( Complex c) { double x = creal(c), y = cimag(c); return x*x + y*y; }

//  0.0  ... r ...       1.0
//   |<------->|<-------->|
//       p0         p1
//
void M( Complex a[]) { // measure

   double r = rand() / (RAND_MAX + 1.0); // 0.0 <= r < 1.0

   double p = abs2( a[0]);

   if( r < p) { printf( "M = 0\n"); a[0] = 1; a[1] = 0; }

   else       { printf( "M = 1\n"); a[0] = 0; a[1] = 1; }
}