/* FILE: randStompField.cpp last change: 30-Jul-2013 author: Romeo Rizzi * This program generates a random mxn Stomp field of 3 values: 0,1,2. * The field is designed has to be devided into several regions by enforcing * the presence of k-spaced stripes * Usage syntax: * > randStompField.cpp m n k seed * * * Usage example: * > randStompField 10 10 3 777 */ #include #include #include #include using namespace std; int RandNumber(int min, int max) { /* returns an integer in [min, max] * see Stroustrup "The c++ Programming Language" 3th edition pg. 685 * for comments on the following manipulation choice. * In particular, considerations on the bad quality of low bits come into account. */ return min + (int) ( (max-min +1) * (double( rand()-0.000000000001 ) / RAND_MAX ) ); } int main(int argc, char** argv) { srand(time(NULL)); int m = atoi(argv[1]); int n = atoi(argv[2]); int k = atoi(argv[3]); if(argc > 4) srand( atoi(argv[4]) ); cout << m << " " << n << endl; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) if( (i+j) % k == 0 ) cout << 2 << " "; else cout << RandNumber(0, 2) << " "; cout << endl; } return 0; }