Search code examples
javascriptrandomdistributionnumber-theory

What's the linear equivalent of this exponential distortion of random distribution?


I got this answer earlier today for how to distort a random number seed toward one bound of the range:

var random = Math.pow(Math.random(), 2);

But that obviously distorts it along an exponential curve.. How can I make it linear?

Also, kind of relevant: I just created this simple script to visualize different types of distributions. It may be helpful for this question: http://jsfiddle.net/RTbrL/


Solution

  • It sounds like you are describing a one-sided triangular distribution.

    If so, try

    var random = 1.0 - Math.sqrt(Math.random());
    

    or

    var random = Math.abs(Math.random() - Math.random());