Choosing random ints, favouring large/small

Thanks, but in addition, I was hoping to get a brief verbal summary of what @Nechoj ‘s function intends to do. I need the bird’s-eye-view layman’s intuitive explanation to accompany the drawn-out analytical explanation when working through others’ code because of my rustiness.

If my understanding is correct as far as it goes, it would also be helpful to have that affirmed: it returns a random number in the range, but it biases the choice to the left or right by the weighting factor

Ok, here it is. The normal `rand` function produces float numbers in the interval [0, 1] with equal probabilities. The modified `rand` function with weight parameter w modifies the probabilities as follows:

• w=0: same as `rand` without parameter weight
• w=1: maximum weight increasing the probabilities for higher numbers. Values near 1 will have double probabilitiy (+100%) compared to values near 0.5 and values close to 0 will have a probability close to 0.
• w=-1: maximum weight increasing the probabilities for low numbers. Values near 0 will have double probabilitiy (+100%) compared to values near 0.5, and values close to 1 will have a probability close to 0.
• w=0.5: medium weight. Values near 1 will have +50% probabilitiy compared to values near 0.5 and values close to 0 will have probability -50% compared to values close to 0.5.

And so on.

2 Likes