Boost logo

Boost :

From: Cromwell Enage (sponage_at_[hidden])
Date: 2004-06-24 13:52:58

Hello, Darren.

--- Darren Cook <darren_at_[hidden]> wrote:
> What I wanted to do was generate a random number in
> the full range of an integer template parameter,
> e.g. whether I used the template with unsigned char,
> or a 128-bit integer. (in the end I decided
> to come back to this when I needed that flexibility
> and implemented using 32-bit integers and the
> standard library's srand48() and mrand48()).
> So, can Boost.Random generate a random number to
> match the type?

This should be possible. Try


as your distribution. (The extra parentheses arise
from a recent thread on using min/max.) For a
user-defined type such as your 128-bit integer, you'll
have to provide a template specialization of
std::numeric_limits before creating the distribution.

Make sure your base rng engine can actually cover at
least the integer range specified in
std::numeric_limits; boost::mt19937 should be good
enough for your purposes.

                              Cromwell Enage

Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!

Boost list run by bdawes at, gregod at, cpdaniel at, john at