SOURCE FILE: makePRandSeq.cpp
/* (include and 'using' directives revised 09/23/2003) */
/*
This program makes a pseudo-random sequence of integers.
You can compile it like this:
g++ -o makePRandSeq makePRandSeq.cpp
then call it like this:
makePRandSeq 37
and it writes 37 (or whatever you said) numbers for you, ten per
line on standard output. The numbers will be between 0 and 999
(inclusive).
*/
#include <sched.h>
#include <time.h>
#include <assert.h>
#include <iostream>
#include <iostream>
using namespace std;
extern long random(void);
const int upperBound = 999 ;
const int lowerBound = 0 ;
const int numPerLine = 10 ;
/* ################################################## */
/* init */
/* ################################################## */
void init()
{
/* initialize random number generator */
srandom(time((time_t *) 0));
}
/* ################################################## */
/* main */
/* ################################################## */
int main(int argc, char * argv[] )
{
init();
int i ;
assert(argc>1) ;
int howMany = atoi(argv[1]) ;
int numPossible = upperBound - lowerBound + 1 ;
cout << endl ;
cout << endl ;
for (i = 0; i < howMany; i++)
{
cout << (random()%numPossible + lowerBound) ;
if (i%numPerLine == numPerLine-1) cout << endl ;
else cout << "\t" ;
}
cout << endl ;
cout << endl ;
return 0 ;
}