Weighted/Biased Random Number Generation with JavaScript based on Probability
codetheory.in
codetheory.in
(0,a,a+b,a+b+c)
random() gives values in [0,1], so divide your numbers by a + b + c.
Generating random structures is the tip of a very big iceberg.
>var list = ['javascript', 'php', 'ruby', 'python']; var weight = [0.5, 0.2, 0.2, 0.1];
You could instead put each into an object: { language: 'javascript', weight: 0.5 }
My code (in the itemRoll function) demonstrates this, but it is a little bit more rolled out because I was instantiating objects: http://humbit.com/rogue/afsahr-v1.2/js/inventory.js