The Boost Random Number Library (Boost.Random for short) provides a variety of generators and distributions to produce random numbers having useful properties, such as uniform distribution. Boost are free peer-reviewed portable C++ source libraries that work well with the C++ Standard Library.
Questions tagged [boost-random]
42 questions
3
votes
1 answer
Consistent random number generation accross platforms with boost::random
We have been using boost::random for sometime now in our projects. Recently, a failing test unit got me intrigued about one of its properties: the sequence of numbers generated across different versions of Boost may be different, depending on the…

André Anjos
- 4,641
- 2
- 27
- 34
3
votes
2 answers
boost::uniform_on_sphere suddenly fails after a few million correct realizations, but only on certain hosts
The Problem
After correctly generating random vectors in 2 dimensions for a while, the boost::uniform_on_sphere distribution suddenly generates a vector with values -nan.
I have tested the included program on three machines- the error was observed…

rngantner
- 41
- 5
2
votes
2 answers
Is boost::random::discrete_distribution dynamically resizable?
I cannot find much documentation of the Boost version of discrete_distribution. After much Google searching, I still can't even find a list of methods that this class has, and whether any of them function to re-assign the probabilities.
In my case,…

ely
- 74,674
- 34
- 147
- 228
2
votes
1 answer
How bad rand from stdlib.h is?
I'm making a monte carlo simulation in C++ and I was using Boost for random numbers. I used GSL a bit too. But it turns out random number generation is one of my biggest runtime inefficiencies, so I just started using good old rand() from cstdlib.…

Rafael S. Calsaverini
- 13,582
- 19
- 75
- 132
2
votes
1 answer
standard multivariate normal random vector using Boost::random
I would like to generate random points on a 2D surface, distributed around a x0, y0 coordinate.
I understand that what I need to generate is called "standard multivariate normal random vector", but I don't know how to do it in C++, for example…

hyperknot
- 13,454
- 24
- 98
- 153
2
votes
3 answers
boost::random and boost:uniform_real works with doubles not with floats?
Pardon me if this has been discussed already. I've got a template function which uses boost::uniform_int and boost::uniform_real depending on the template argument and should return the same type:
template N getRandom(int min, int…

Ælex
- 14,432
- 20
- 88
- 129
2
votes
2 answers
boost random in 2 dimensions
I am trying to use a boost random generator to make random points uniformly distributed over a plane surface. I have the following link for doing it in a single dimension:
Boost random number generator
Here they use boost::uniform_int<> to…

sekaran
- 31
- 6
2
votes
1 answer
Getting integer random values instead of real values using boost::random library
I am trying to get real random values using boost::random libraries. This is my code:
#include
#include
#include
boost::random::mt19937 eng =…

Andry
- 16,172
- 27
- 138
- 246
1
vote
0 answers
random number using Normal distrubution in C++
As explained by John, I tried this:
#include
std::tr1::mt19937 eng; // a core engine class
std::tr1::normal_distribution dist;
for (int i = 0; i < 10; ++i)
std::cout << dist(eng) << std::endl;
But I am getting…

Kaushik Acharya
- 1,520
- 2
- 16
- 25
1
vote
3 answers
Initializing a member class of an object using a non-default constructor in C++
I have a specific situation where I've got an object that I want to use the boost random number generators on, and it has lead to a greater question which I cannot seem to answer. Here is the example code of what I'm trying to produce.
First, my…

Avacar
- 87
- 1
- 7
1
vote
2 answers
Boost random numbers - weird compilation error
In a simulation I'm writing I have a class that represents an Agent that must take some actions and I want this agent to have access to a random number generator. I heard boost rng's where good ones, so I wanted to learn how to use them.
So, here's…

Rafael S. Calsaverini
- 13,582
- 19
- 75
- 132
1
vote
1 answer
How do I use Boost Random
I need to generate random number with Boost Random.
I tried to follow the general guide.
I extracted the files of the library. So if I want to use the classes and objectj of the library how I should do?
First I know including the library in the…

Andrea Angeletti
- 271
- 4
- 12
1
vote
1 answer
Undefined reference to boost::random::random_device constructor and destructor on MinGW-w64 gcc
My OS is Windows 7 64-bit and C++ compiler I'm using is:
g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.3.0
And I installed Boost version 1.60 using:
bootstrap.bat mingw
b2 install target=gcc
Then I tested is it working, using examples…

Toreno96
- 1,541
- 2
- 14
- 14
1
vote
1 answer
How to reset Boost::variate_generator distribution?
I am trying to write a function that takes in a min and a max and returns a random double between them. I was trying to use Boost::variate_generator to get a random number between two doubles, but the issue is that I can't change the distribution on…

user947871
- 339
- 6
- 17
1
vote
2 answers
Issue when shuffling a vector with boost::random
I am using this code to generate a random permutation of a vector using a variation of Fisher-Yates randomization algorithm (I am going from the first element to the last, not the other way around). I am using a boost::random::mt11213b RNG globally…
user267885