I am looking for a simple algorithm how to generate pseudo-random floating point numbers using only ANSI rand() function but with arbitrary probability distribution. For a simple uniform distribution I use following code:
x = (float)rand() / (float)RAND_MAX;
Of course it is not very accurate, but enough for my needs. I need also other distributions like logistic and gaussian. Ideally I have to define an arbitrary pdf using a simple vector of finite length, e.g. for logistic pdf this vector may look like:
logistic_pdf = {0., 0.26894, 0.33924, 0.41742, 0.5, 0.58257, 0.66075, 1.};
and for uniform (using same dimensionality 8):
uniform_pdf = {0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125};
This is only an idea. But I am not sure how to implement it efficiently using rand()->{0...RAND_MAX} only.
there is no simple algorithm to do arbitrary complex things. you have to find the inverse probability integral transform for each of your ‘arbirary’ distributions.