My question is an extension of this question: Weighted random numbers
I'm trying to implement a weighted random numbers. I'm currently just banging my head against the wall and cannot figure this out.
In my project (Hold'em hand-ranges, subjective all-in equity analysis), I'm using Boost's random -functions. So, let's say I want to pick a random number between 1 and 3 (so either 1, 2 or 3). Boost's mersenne twister generator works like a charm for this. However, I want the pick to be weighted for example like this:
1 (weight: 90) 2 (weight: 56) 3 (weight: 4)
Does Boost have some sort of functionality for this?
The extension: the user is allowed to dynamically change the weight of a given key.
How does one optimally solve the problem?
The naive solution might be to scan through all elements, adjust the weight of all elements based on the new weight...but that's O(n) for the update. It's very inefficient. How do we do better?
I want update(key, w)
and get()
to be better than or equal to O(logn)
discrete_distribution
in the Boost.Random documentation? – Shawnstd
now. – Evgdiscrete_distribution
has no interface to change probabilities. The only way is to create a newdiscrete_distribution
. – Evg