MV Normal distribution RNG plugin

I would like to request a simple plugin where you can set the min/max value and skew and it will output an integer and save it to X variable. My goal is to make RNG in my game more normalized.

example:
Plugin Command: NormalCurve (min, max, variable)
Plugin Command: NormalCurve (20, 100, 4) would generate a random integer between 20 and 100 and save it to variable 4.
Let me know if it works, I didn't test it as it contains just a few lines of code.

MZ users: Simply do a Plugin Command

MV & MZ users: Do a JS Code and insert
Code:
randomNumber(min, max, variableId)
e.g.
Code:
randomNumber(10, 200, 4)
Just create an empty JS file and stick this in there:

JavaScript:
function rnd_num(param1, param2, variable) {
 
    var min = Math.min(Math.abs(param1),Math.abs(param2));
    var max = Math.max(Math.abs(param1),Math.abs(param2));
 
    var randomNumber = min + Math.randomInt(max+1-min);
 
    $gameVariables.setValue(variable, randomNumber);
 
};

Then you can use the function
JavaScript:
rnd_num(param1, param2, variable);
by using the "script-call" command.

Just put in any two numbers in any order and it will save a random number between the smaller and the bigger number in the desired variable.

edit: ninja'd
Both of the above solutions are non-skewed/uniform distributions, which is easily done with existing event commands or a simple min + Math.randomInt(max - min + 1) script call.

When referring to a probability distribution, the word "normalised" means that if you multiply every possible output value by its probability over the distribution's domain, the answer is 1 (i.e. 100%). This has nothing to do with the normal (a.k.a. Gaussian) distribution.

Incidentally, the normal distribution is typically used for analysing a data set, rather than generating or skewing random numbers. Hence its characterisation in terms of mean and standard deviation.

You can naively skew a uniform RNG by passing the uniform value through the skew function, e.g. skewing Math.random (uniform on [0, 1)) through f(x) = x²:
JavaScript:
Math.pow(Math.random(), 2)
Then you can do the usual multiplying/rounding to get whatever kind of value you like. However, this does not guarantee that the skewed RNG will be normalised.

I think this represents a Gaussian curve? 😅
JavaScript:
function gaussian(x, mean, dev) {
    // exp(-(x-μ)²/2σ²) / σ√2π
    return Math.exp(
        -Math.pow((x - mean) / dev, 2) / 2
    ) / (dev * Math.SQRT1_2 / Math.sqrt(Math.PI));
}
So in theory you may be able to use that. I'd suggest using a polynomial or something instead, though. If you want to normalise the Gaussian-skewed result then things get complicated because that curve's integral requires numerical approximation.

(Hopefully I haven't misinterpreted and written that all out for nothing. 😴)
Hey, everyone. Unfortunately, I can't provide a function for normal-distributed random numbers (I'm looking for one myself), however, I've just spent 3 hours making a tool that should help with testing the function itself: https://nolonar.github.io/DistributionGrapher/webapp/

Simply enter a function and click on the "Test function" button to see how the generated numbers are distributed.

For example, following function:
JavaScript:
Math.pow(Math.random(), 2)

will result in the following distribution:
Screenshot 2022-05-21 013558.png


Have fun with the tool, and I hope you'll be able to come up with satisfactory normal-distributed RNGs.


EDIT:
I just found a function that approximates a normal distribution well enough:
Screenshot 2022-05-21 014806.png


It's basically just adding 6 random numbers together.
Thanks everyone I ended up combining parts of everyone's answers to get exactly what I want.

Original thread: https://forums.rpgmakerweb.com/threads/normal-distribution-rng-plugin.147771/