Return to Snippet

Revision: 1294
at September 27, 2006 10:29 by gdonald


Updated Code
#include <iostream>
#include <cstdlib>
#include <ctime>

int main(int argc, char *argv[]){
        if(argc != 3){
                cout << "Usage: " << endl;
                cout << "       rand [int x] [int y]" << endl;
                cout << "       [x] = highest possible value of a random number" << endl;
                cout << "       [y] = quantity of random numbers created" << endl << endl;
                exit(1);
        }
        long int M = atoi(argv[1]);
        int quantity = atoi(argv[2]);
        srand(time(NULL));
        for(int count = 1; count <= quantity; ++count)
                cout << (((int)(((double)rand()/(double)(RAND_MAX+1))*M))*-1)+1 << endl;
        return 0;
}

Revision: 1293
at September 27, 2006 10:29 by gdonald


Initial Code
#include <iostream>
#include <cstdlib>
#include <ctime>

int main(int argc, char *argv[]){
        if(argc != 3){
                cout << "Usage: " << endl;
                cout << "       rand [int x] [int y]" << endl;
                cout << "       [x] = highest possible value of a random number" << endl;
                cout << "       [y] = quantity of random numbers created" << endl << endl;
                exit(1);
        }
        long int M = atoi(argv[1]);
        int quantity = atoi(argv[2]);
        srand(time(NULL));
        for(int count = 1; count <= quantity; ++count)
                cout << (((int)(((double)rand()/(double)(RAND_MAX+1))*M))*-1)+1 << endl;
        return 0;
}

Initial URL

                                

Initial Description

                                

Initial Title
C++ random number generator

Initial Tags
number

Initial Language
C++