/* FILE: randMatrix.cpp last change: 3-Jul-2014 author: Romeo Rizzi * randomly generates a random nxn matrix of integers in the range [minV,maxV] with all elements in last column at maxV. * Usage syntax: * > randMatrix n minV maxV seed */ #include #include #include #include using namespace std; int n, minV, maxV, seed; int RandNumber(int min, int max) { return min + (int) ( (max-min +1) * (double( rand()-0.000000000001 ) / RAND_MAX ) ); } int main(int argc, char** argv) { n = atoi(argv[1]); minV = atoi(argv[2]); maxV = atoi(argv[3]); srand(time(NULL)); if(argc > 4) srand( atoi(argv[4]) ); cout << n << endl; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { int tmp = RandNumber(minV, maxV); if( j == n-1 ) cout << maxV << " "; else cout << tmp << " "; } cout << endl; } return 0; }