I need a weighted random number generator, to which you pass a function, the low and high values, and a peak value. So you can ask for uniform distribution (trivial); or for a triangle function using low, high, and peak; or a similar function but where the sides of the triangle are curved, or for a trig function, with its highest value coincident with peak, etc.
The literature includes several algorithms for weighted random number generation, but as far as I can tell, none which would allow these various functions to be manifested. I really don't want to use the brute-force method of creating an array with many entries for a high-probability choice, and few for low-probability ones, because I need to use this very frequently in a large program, and the low, high, and peak values will seldom be repeated.
Aucun commentaire:
Enregistrer un commentaire