// 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; } }