/* FILE: randStomp2Field.cpp last change: 30-Jul-2013 author: Romeo Rizzi * This program generates a random mxn Stomp field of 2 values: 0,1. * Usage syntax: * > randStompField.cpp m n 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]); if(argc > 3) srand( atoi(argv[3]) ); cout << m << " " << n << endl; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) cout << RandNumber(0, 1) << " "; cout << endl; } return 0; }