Random: Using random generators with runtime parameters

Hi! How can I use random generators with multiple parameters such as linear_congruential with parameters that are only known at runtime? Thanks in advance, Hans

Hans Mull
Hi! How can I use random generators with multiple parameters such as linear_congruential with parameters that are only known at runtime?
Thanks in advance, Hans
I've often wondered this myself (not the how, but the why). This is a rather odd feature of the Boost Random library. Most libraries would have a function list "rnorm(mean, std)" which would return a random deviate with the specified mean and standard deviation. Changing these at runtime is important for many kinds of simulation. You can of course define these yourself eg double rnorm(double mean, double std) { return std * rnorm01() + mean; } where rnorm01() returns deviates with unit scaling and zero mean. This works if the scaled distribution is affine to the original, but does not work otherwise (if the distribution changes shape with the parameters). This is an area where Boost Random needs some TLC. Good idea for a SoC project! THK

On 25 Mar 2008, at 19:53, Tim Keitt wrote:
I've often wondered this myself (not the how, but the why). This is a rather odd feature of the Boost Random library. Most libraries would have a function list "rnorm(mean, std)" which would return a random deviate with the specified mean and standard deviation. Changing these at runtime is important for many kinds of simulation. You can of course define these yourself eg
double rnorm(double mean, double std) { return std * rnorm01() + mean; }
where rnorm01() returns deviates with unit scaling and zero mean. This works if the scaled distribution is affine to the original, but does not work otherwise (if the distribution changes shape with the parameters).
This is an area where Boost Random needs some TLC. Good idea for a SoC project!
Distributions in Boost.Random do just that. Matthias

Matthias Troyer
On 25 Mar 2008, at 19:53, Tim Keitt wrote:
I've often wondered this myself (not the how, but the why). This is a rather odd feature of the Boost Random library. Most libraries would have a function list "rnorm(mean, std)" which would return a random deviate with the specified mean and standard deviation. Changing these at runtime is important for
Distributions in Boost.Random do just that.
Matthias
Matthias, just noticed your reply. Could you provide and example. All I see is eg variate = lognormal_distribution(mean, var)(). Is that what you had in mind? It seems odd that the parameters are provided as arguments to a constructor rather than a simple function call. THK

On 25 Mar 2008, at 00:09, Hans Mull wrote:
Hi! How can I use random generators with multiple parameters such as linear_congruential with parameters that are only known at runtime?
This is not done because usually only a very small set of parameters gives acceptable random number generators, and they can all be known at compile team. I wonder what application you have in mind that requires parameters to be changed at runtime? Matthias
participants (3)
-
Hans Mull
-
Matthias Troyer
-
Tim Keitt