Modding:NatFloat

From Vintage Story Wiki
This page contains changes which are not marked for translation.

This page was last verified for Vintage Story version 1.19.8.

A somewhat more natural random number generator. The main difference to pure random is that you can define a distribution to influence how often certain values are chosen.

Arguments

  • avg: Average value
  • var: Variation
  • dist: Distribution type
Overview - Distribution modes
Name Explanation
uniform Select a random number between the value of avg-var and the value of avg+var (the default distribution).
triangle Select a random number with numbers near avg being the most commonly selected ones, following a triangle curve.
gaussian Select a random number with numbers near avg being the most commonly selected ones, following a gaussian curve.
narrowgaussian Select a random number with numbers near avg being the most commonly selected ones, following a narrow gaussian curve.
verynarrowgaussian Select a random number with numbers near avg being the most commonly selected ones, following a very narrow gaussian curve.
inversegaussian Select a random number with numbers near avg being the least commonly selected ones, following an upside down gaussian curve.
narrowinversegaussian Select a random number with numbers near avg being the least commonly selected ones, following an upside down narrow gaussian curve.
invexp Select a random number between the value of avg and the value of avg+var, with numbers near avg being preferred
stronginvexp Select a random number between the value of avg and the value of avg+var, with numbers near avg being strongly preferred
strongerinvexp Select a random number between the value of avg and the value of avg+var, with numbers near avg being very strongly preferred
dirac Select a random number between the value avg-var and avg+var only ONCE and then always 0.


Here are some plots for these distributions. They are created by generating 8000 random numbers between 0 and 200, where the X-Axis is the resulting value and the Y-Axis the amount of times this value was chosen.

Natfloat-uniform.png Natfloat-triangle.png Natfloat-gauss.png Natfloat-narrowgauss.png Natfloat-verynarrowgauss.png

Natfloat-invgaus.png Natfloat-narrowinvgaus.png Natfloat-invexp.png Natfloat-stronginvexp.png Natfloat-stronverinvexp.png

Translated to the Natfloat arguments the horizontal center point in these graphs denote the "avg" value, the width of the plot is determined by the "var" value. In json, the uniform distribution would be in the written as such:
{ avg: 100, var: 100, dist: "uniform" }


See also EvolvingNatFloat