random.cpp
Demo in class April 3, 2008


#include <iostream>
#include <cstdlib>

using namespace std;



int main( )

{
        cout << endl << "Ramdom Number Program" << endl << endl;
        
        int i;
        for(i = 0; i < 10; i++)
                cout << rand() << "\t";

        
        cout << endl << endl <<"Now let's scale: " << endl;

        for(i = 0; i < 10; i++)
                cout << (rand() % 11) << "\t";
        cout << endl;

        for(i = 0; i < 10; i++)
                cout << (RAND_MAX - rand())/static_cast<double>(RAND_MAX) << "\t";

        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);

        cout << endl;

        for(i = 0; i < 10; i++)
                cout << (RAND_MAX - rand())/static_cast<double>(RAND_MAX) << "\t";

        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(1);

        cout << endl;

        for(i = 0; i < 10; i++)
                cout << (RAND_MAX - rand())/static_cast<double>(RAND_MAX) << "\t";

        cout << endl << endl <<"Now let's seed: " << endl;

        cout << "The seed is 99" << endl;
        srand(99);
        for(i = 0; i < 10; i++)
                cout << (rand() % 11) << "\t";

        cout << endl << "The seed is 55" << endl;
        srand(55);
        for(i = 0; i < 10; i++)
                cout << (rand() % 11) << "\t";

        cout << endl << "The seed is 99" << endl;
        srand(99);
        for(i = 0; i < 10; i++)
                cout << (rand() % 11) << "\t";


        cout << endl;
        return 0;
}