Boost logo

Boost Users :

Subject: Re: [Boost-users] How do I use random_device?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-09-07 10:44:25


AMDG

Raphael MD wrote:
> I need to use random_device for generating non deterministic random numbers, but
>
> I don't know how to use this class, it's very confusing, I don't understand it.
>
> I'm using linux.
>
> My example code:
>
> using namespace std;
> #include <iostream>
> #include <string>
> #include <boost/timer.hpp>
> #include <boost/nondet_random.hpp>
>
>
> int main()
> {
> boost::random_device::result_type min(1);
> boost::random_device::result_type max(60);
> boost::random_device dev;
> }
>
> Thanks for help.
>

I assume you want to generate numbers in the range [1,60]?
All generators including random_device produce values
is a predefined range. To produce values in the range you
want, use uniform_int. There's an example at
http://www.boost.org/doc/libs/1_44_0/doc/html/boost_random/tutorial.html.
It uses mt19937, but the usage with random_device is
the same.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net