# include # include int flip ( ); void gray ( int m, int n, int g[m][n] ); int locate ( int n, float x ); int main ( ) { int i; int i1; int j; int j1; int n; float x; float y; n = 500; int cell[n][n]; for ( i = 0; i < n; i++ ) { for ( j = 0; j < n; j++ ) { cell[i][j] = 0; } } x = ( float ) rand ( ) / ( float ) RAND_MAX; y = ( float ) rand ( ) / ( float ) RAND_MAX; printf ( "Starting at (%g,%g).\n", x, y ); for ( i = 0; i < 100000; i++ ) { j = flip ( ); if ( j == 0 ) { x = x / 2.0; y = y / 2.0; } else if ( j == 1 ) { x = ( x + 1.0 ) / 2.0; y = y / 2.0; } else { x = x / 2.0; y = ( y + 1.0 ) / 2.0; } i1 = locate ( n, x ); j1 = locate ( n, y ); cell[i1][j1] = 1; } bw ( n, n, cell ); return 0; } int flip ( ) { int value; value = rand ( ) % 3; return value; } int locate ( int n, float x ) { int value; value = ( int ) ( x * n ); return value; }