/* FILE: creaFile.cpp last change: 12-Mar-2001 author: Romeo Rizzi * This program generates a sequence of n random (unsorted) integers. * Usage syntax: * > creafile */ #include #include #include long int RandNumber(long int max, long int min) { /* 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 + (long int) ( (max-min) * (double(rand()) / RAND_MAX) ); } main(int argc, char** argv) { srand (time(NULL)); // initialize the pseudo-random generator long int n; cout << "Quanti numeri vuoi?: "; cin >> n; long int min; cout << "MIN ?: "; cin >> min; long int max; cout << "MAX ?: "; cin >> max; for(long int i = 1; i <= n; i++) cout << RandNumber(max, min) << endl; }