RNGesus

Custom Probability Distribution

RNGesus Allows you to create frequency distribution curves. Generate distribution curve assets that can then be used as your random number source.

Usage

Creating a distribution curve asset

From the Unity Editor menu select Assets->Create->RNGesus->Distribution Curve

Give the newly created asset a name in the project window. Then select it and from the inspector panel, adjust the curve to the shape you want. The higher the point on a curve, the higher chance that a random number will come from that area.

Please look in RNGesus/Examples/ directory for more example curves

Using in your code

Add in the RNGesus namespace at the top of your script.

using Entropedia.RNGesus

Add a variable to reference the Distribution Curve you’ve created.

public class TreeSpawner {

  public DistributionCurve treeSizeCurve;
  

To get a random number, call the Random method on the distribution curve variable.

public void Spawn(){
  var tree = Instanciate(treePrefab);
  tree.transform.localScale = treeSizeCurve.Random() * Vector3.one;
}

Congratulations, you’re done!

Advanced Features

If you want to use DotNets Random Number Generator instead of Unity’s then please select you asset in the project window, then in the inspector change the RNG type to “DotNet”.

Seeding for DotNet

When using DotNet, to seed a distribution curve call the Seed setter like so:

  treeSizeCurve.Seed = 5838292596;

Seeding for Unity.Random

Simple use Random.InitState method to seed the values generated by your distribution curves.