Generate random numbers with less probabilities of bigger numbers

javascript, random

Solution

Square the result of `Math.random`:

var result = Math.random();
result = result * result;
result *= 100;
result = Math.floor(result);

You can adjust the curve by adjusting the exponent. Here's a few graphs of different exponents:

If you're going to use a non-integer exponent, you'll need to use `Math.pow`.

Problem

I want to implement a random number generator which lets me set the maximum number I want but also lets me tweak the probabilities to make it harder to get bigger number. Using this would allocate the same probabilities to any value in the range of 100. ``` Math.floor(Math.random()*100); ``` How can I make numbers get progressively harder to appear as the number gets closer to the limit (100)?

Original source