/* FILE: randStrip2n.cpp last change: 10-Feb-2015 author: Romeo Rizzi * This program generates a 2xn strip of random integers. * Usage syntax: * > randStrip2n out_file n seed */ #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) * (double(rand()) / RAND_MAX) ); } int main(int argc, char** argv) { srand(time(NULL)); int n, MIN_VAL = -9, MAX_VAL = 9; n = atoi(argv[2]); if(argc > 3) srand( atoi(argv[3]) ); ofstream fout(argv[1]); fout << n << endl; for(int i = 1; i <= n; i++) fout << RandNumber(MIN_VAL, MAX_VAL) << " "; fout << endl; for(int i = 1; i <= n; i++) fout << RandNumber(MIN_VAL, MAX_VAL) << " "; fout << endl; fout.close(); return 0; }