// This program uses the class RandGen found in rando.cpp and rando.h
// You can use it to give you many different ranges. There are also examples
// for formatting output.
//
// RandGen() --- constructor sets seed of random # generator
// once per program, not per class/object
//
// RandInt(int max)
// RandInt(int low,int max) - return random integer in range [0..max)
// when one parameter used, [low..max] when
// two parameters used
//
// examples: rnd.RandInt(6) is random integer [0..5] or [0..6)
// rnd.RandInt(3,10) is random integer [3..10]
// rnd.RandInt() is random integer [0..INT_MAX)
//
// RandReal() -- returns random double in range [0..1)
// RandReal(double low, double max)
// -- returns random double in range [low..max)
#include <iostream>
#include <iomanip>
#include <vector>
#include "rando.h"
using namespace std;
//prototypes
void fill (vector<double>& v); // The '&' is an ampersand and indicates the variable
void display (vector<double> & v); // following it can be changed by the function. If there
// is no '&' the parameter is passed by value and cannot
// be changed by the function.
int main()
{
int length=200;
vector<double> list(length,0); // Defines a vector with size (200) elements and fills with 0
fill(list);
display(list);
return 0;
}
void display (vector<double> & v) // vectors are frequently passed to functions by
{ // by reference ( there is an &). The "&" allows
int i; // the contents of the variable to be changed and
for ( i=0;i<v.size();i++) // saves storage, because no local array is made.
{
cout<<setiosflags(ios::fixed|ios::showpoint)//sets flags so that the precision can be set
<<setw(8) //sets field width of 8
<<setprecision(2) //two decimal places will be shown
<<v[i];
if (i%10== 9){cout<<endl;} //starts a new row after 10 numbers have been printed
}
cout<<endl<<endl;
}
void fill (vector<double> & v) // & must be used to have the new values put into the
{ // vector "list" created in the main program.
int i;
RandGen r;
for ( i=0;i<v.size();i++)
{
v[i] = r.RandReal(5,20); // chooses a random decimal between 5 and 20
}
}