boost::minstd_rand usage

A

Alex Vinokur

Hi,

I need to generate randomal integers (0 - 2^31) with
boost::minstd_rand.

Any sample of minstd_rand usage?
[snip]

#include <iostream>
#include <iterator>
#include <vector>
#include <set>
#include <boost/random.hpp>
#include <boost/config.hpp>

int main()
{
const size_t totalGeneratedNumbers = 0x200000;

std::vector<unsigned int> v;

boost::minstd_rand m;

mr.seed (0x12345678);

std::generate_n( std::back_inserter(v), totalGeneratedNumbers, m);

const std::set<unsigned int> s (v.begin(), v.end());

if (s.size() == v.size())
{
std::cout << "No number repetitions" << endl;
}
else
{
std::cout << "There are number repetitions" << endl;
}


return 0;
}


Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top