NatFloat: Difference between revisions

From Vintage Story Wiki
2,657 bytes added ,  1 month ago
m
Updated navbox to new code navbox.
No edit summary
m (Updated navbox to new code navbox.)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
A somewhat more natural random number generator.
{{GameVersion|1.19.3}}
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.


If you create 8000 random numbers between 0..200 and plot them, where the X-Axis is the resulting value and the Y-Axis the amount of times this value was returned then you can see how the random number generator behaves. These are some simple plots for all distributions. Uniform is just your normal average random number generator.
'''Arguments'''
 
* '''avg''': Average value
* '''var''': Variation
* '''dist''': Distribution type
 
<table class="wikitable">
  <tr>
<th colspan="2">Overview - Distribution modes</th>
  </tr>
  <tr style="background-color: rgba(0,0,0,0.2);">
    <th style="background-color: rgba(0,0,0,0.2);">Name</th>
<th style="background-color: grey;">Explanation</th>
  </tr>
  <tr>
    <td>uniform</td>
<td>Select completely random numbers within avg-var until avg+var (the default distribution).</td>
  </tr>
  <tr>
    <td>triangle</td>
<td>Select random numbers with numbers near avg being the most commonly selected ones, following a triangle curve.</td>
  </tr>
  <tr>
    <td>gaussian</td>
<td>Select random numbers with numbers near avg being the most commonly selected ones, following a gaussian curve.</td>
  </tr>
  <tr>
    <td>narrowgaussian</td>
<td>Select random numbers with numbers near avg being the most commonly selected ones, following a narrow gaussian curve.</td>
  </tr>
  <tr>
    <td>verynarrowgaussian</td>
<td>Select random numbers with numbers near avg being the most commonly selected ones, following a very narrow gaussian curve.</td>
  </tr>
  <tr>
    <td>narrowinversegaussian</td>
<td>Select random numbers with numbers near avg being the least commonly selected ones, following an upside down gaussian curve.</td>
  </tr>
  <tr>
    <td>inversegaussian</td>
<td>Select random numbers with numbers near avg being the least commonly selected ones, following an upside down gaussian curve.</td>
  </tr>
  <tr>
    <td>narrowinversegaussian</td>
<td>Select random numbers with numbers near avg being the least commonly selected ones, following an upside down narrow gaussian curve.</td>
  </tr>
  <tr>
    <td>invexp</td>
<td>Select numbers in the form of avg + var, wheras low value of var are preferred.</td>
  </tr>
  <tr>
    <td>stronginvexp</td>
<td>Select numbers in the form of avg + var, wheras low value of var are strongly preferred.</td>
  </tr>
  <tr>
    <td>strongerinvexp</td>
<td>Select numbers in the form of avg + var, wheras low value of var are very strongly preferred.</td>
  </tr>
<tr>
    <td>dirac</td>
<td>Select completely random numbers within avg-var until avg+var only ONCE and then always 0.</td>
  </tr>
</table>
 
 
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.  


[[File:Natfloat-uniform.png]]
[[File:Natfloat-uniform.png]]
[[File:Natfloat-triangle.png]]
[[File:Natfloat-triangle.png]]
Line 15: Line 80:
[[File:Natfloat-stronginvexp.png]]
[[File:Natfloat-stronginvexp.png]]
[[File:Natfloat-stronverinvexp.png]]
[[File:Natfloat-stronverinvexp.png]]
<br><br>
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: <br><code>{ avg: 100, var: 100, dist: "uniform" }</code>
See also [[EvolvingNatFloat]]
{{Navbox/codemodding}}
Confirmedusers
575

edits