Given a list of random numbers [0, 1]: can I use the standard library to convert to a specific distribution?

Viewed 81

I have an std::vector<double> or random numbers [0, 1]. (How) Can I use the standard library to convert it to a specific (e.g. Weibull) distribution (using the distribution's cumulative distribution)?

To be clear: I don't have what the standard library considers a "generator" (I don't have a class whose operator() returns an integer). I already have a list of random doubles [0, 1] and want to just use the standard library's implementation of the cumulative density function of the different distributions (e.g. Weibull).

2 Answers

No you can't, not without iterative techniques.

The standard library is not quite a mathematics package. You need the quantile function for the desired distribution in order to convert a uniform drawing in [0, 1) (perhaps [0, 1] if you're lucky) to your distribution, and the standard library doesn't specify those functions. Note that the quantile function is the inverse of the cumulative distribution function.

Having faced exactly this problem in the past, I resorted to functions from the Boost distribution.

I don't have what the standard library considers a "generator" (I don't have a class whose operator() returns an integer)

So make one!

A little class that reads your list of random numbers and then outputs the "next" one when () is called.

Related