I'm looking for a random distribution which allows me to generate
enums with specified probabilities.
As a simple example I could have:
//The enum.
typedef enum {vt_car, vt_bus, vt_walk, vt_cycle} vehicle_types;
//What I want to generate and the associated probabilities.
boost::array
At 1:12 PM +0100 5/3/08, Kevin Martin wrote:
I'm looking for a random distribution which allows me to generate enums with specified probabilities.
As a simple example I could have:
//The enum. typedef enum {vt_car, vt_bus, vt_walk, vt_cycle} vehicle_types;
//What I want to generate and the associated probabilities. boost::array
items = {vt_car, vt_bus, vt_walk, vt_cycle}; boost::array probabilities = {0.1, 0.2, 0.3, 0.4}
This should be pretty easy to write. I would be tempted to
pass in a "const boost::array < std::pair
On 4 May 2008, at 00:57, Marshall Clow wrote:
This should be pretty easy to write. I would be tempted to pass in a "const boost::array < std::pair
, N>", which would give return values and probabilities; and use a std::vector<double> to calculate cumulative probabilities, and for each call to the RNG, do a binary search in the vector to find the right spot, and then return the associated value.
That's not quite, but almost what I did, after mailing yesterday. I
allow the probabilities (but not the objects) to be changed.
For what I'm actually doing, I need to alter the probabilities quite a
lot so it seemed silly to have to construct a new object.
I tried to write it so it fits in as much as possible with boost/
random so it should be useful for someone else in same situation.
Thanks,
Kevin Martin
template
participants (2)
-
Kevin Martin
-
Marshall Clow