mardi 5 mai 2015

Generating a random number between a range with a weight/bias?

I am trying to generate a random number between 1 and a maximum. This I don't have a problem doing so and do so with the following:

var max = 200;    
var randomNumber = Math.floor(Math.random() * max) + 1;

However in an ideal situation I would like to generate a number between 1 and my maximum however the lower numbers have a higher probability of occurring. I want the variable to be biased towards 1. However my maths skills aren't strong enough to work this out, it would be great if someone could point me in the right direction.

Thank you,

Josh




Aucun commentaire:

Enregistrer un commentaire