boost random

G

Gary Wessle

Hi

using The Boost Random Number Library. how can I get a random number
every time I run the project "./proj"

the code below prints out 10 random numbers but it will print the same
exact numbers every time it runs. I just need one number not 10, and
random "different from the one before".
I can do the first "remove the for loop" but not able to do the
second.

#include <boost/random.hpp>
typedef boost::minstd_rand base_generator_type;
int main(){
base_generator_type generator(42u);
boost::uniform_real<> uni_dist(0,1);
boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni(generator, uni_dist);
for(int i=0; i<10; i++)
std::cout << uni() << std::endl;
}

thanks
 
K

Klaas Vantournhout

I don't know much about the boost library, but is it not possible to
give a seed number. If it is then you can make your seed number
depending on the time when the program starts to run.

Klaas
 
M

Markus Moll

Hi

Klaas said:
I don't know much about the boost library, but is it not possible to
give a seed number. If it is then you can make your seed number
depending on the time when the program starts to run.

Of course it is:

And while 42 is the answer to basically everything, it is not a good seed.
( e.g. clock() might be much better, on UNIces, reading from /dev/random
would provide a good seed )

Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top