Question:

Simple Random Number Generator?

by  |  earlier

0 LIKES UnLike

Hi! I'm new to C++, and I would like to learn how to do a

simple random number generator!

From this code,

#include <iostream>

using namespace std;

void main (void)

{

}

What must I add to turn it into a random number generator,

for let's say, 52 numbers?

 Tags:

   Report

2 ANSWERS


  1. http://www.agner.org/random/randomc.zip

    download that zip of .cpp files

    File list

    randomc.h

    C++ header file containing class definitions.

    You must #include this in all C++ files that use this library.

    mersenne.cpp

    Random number generator of type Mersenne twister.

    ranrotb.cpp

    Random number generator of type RANROT-B.

    ranrotw.cpp

    Random number generator of type RANROT-W.

    mother.cpp

    Random number generator of type Mother-of-all (multiply with carry).

    rancombi.cpp

    Template class for combining any two of these random number generators.

    ex-ran.cpp

    Example showing how to use these random number generators.


  2. include &lt;cstdlib&gt;

    #include &lt;ctime&gt;

    #include &lt;iostream&gt;

    int main()

    {

        srand((unsigned)time(0));

        int random_integer;

        for(int index=0; index&lt;20; index++){

            random_integer = (rand()%10)+1;

            cout &lt;&lt; random_integer &lt;&lt; endl;

        }

    }

    This generates 20 random numbers between 1 and 10.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.