Make It Random

Development Discontinued | Discuss | Basic

Documentation | Quick Start | Changes | Demos

Requires Unity 5.0.0 or higher.

A serious RNG library for serious engineers.

Make It Random is a fast, flexible, extensible, and feature-rich random number generation library. Unlike UnityEngine.Random, Make It Random provides the following benefits:

The categories of random data that Make It Random can generate includes:

In addition, Make It Random includes utilities for the following, with support for non-uniform weights where applicable:

The library is very extensible, to support whatever underlying RNGs and extension functions you might want. Full source code is included.

The basic edition is also available, offering just the core RNG functionality for free!

The Details

Random Engines

Random Integers

Random Floating Point Numbers

Probabilities and Chance

Distribution Sampling

Vectors and Quaternions





List Access and Shuffling


{-1, 0, +1}



The following script can be used to place multiple copies of a prefab into the scene, with random positions selected near the surface of a sphere.

using UnityEngine;
using Experilous.MakeItRandom;

public void SphericalShellDistributor : MonoBehaviour
    public MeshRenderer prefab;
    public int objectCount = 100;
    public string randomSeed = "andy";
    public float minShellRadius = 9f;
    public float maxShellRadius = 11f;
    public float minScale = 0.5f;
    public float maxScale = 1.5f;
    protected void OnStart()
        // Use the seed to create the random engine which
        //   will provide the randomness of each child.
        var random = MIRandom.CreateStandard(randomSeed);
        for (int i = 0; i < objectCount; ++i)
            var meshRenderer = Instantiate(prefab);
            var meshTransform = meshRenderer.transform;
            meshTransform.SetParent(transform, false);
            // Assign a random position within the shell.
            meshTransform.localPosition =
                random.PointWithinSphericalShell(minRadius, maxRadius);
            // Give it a completely random orientation.
            meshTransform.localRotation = random.Rotation();
            // Pick a random scale within the specified range.
            var scale = random.RangeCC(minScale, maxScale);
            meshTransform.localScale = new Vector3(scale, scale, scale);
            // Assign a color pulled randomly from the HCY color space.
            meshRenderer.color = random.ColorHCY();

Here are quick samples from the various categories of random content generation available:

// Initialize random engine with a transient seed
var random = XorShift128Plus.Create();

// Generate an integer where 1 <= n <= 10
int num1to10 = random.RangeCC(1, 10);

// Generate a number where 0 <= n < 1
float num0to1 = random.FloatCO();

// Flip a coin
bool heads = random.Chance();

// Check a 3 in 10 probability
bool criticalHit = random.Probability(3, 10);

// Generate a random height for a male character in cm
float height = random.NormalSample(176f, 8f);

// Generate an angle in degrees where -90 < n < +90
float angleNeg90toPos90 = random.SignedHalfAngleDegOO();

// Generate +1, -1, or 0 where +1 is twice as likely as -1, and 0 is rare
int numPNZ = random.SignOrZero(200, 100, 1);

// Roll 43 20-sided dice
int[] diceRolls = random.RollDice(43, 20);

// Roll 5 4-sided dice and just keep the sum
int diceRollSum = random.SumRollDice(5, 4);

// Shuffle the array of earlier dice rolls

// Select a random die roll from the array
int dieRoll = random.Element(diceRolls);

// Select index where higher die rolls are more likely to be picked
int dieRollIndex = random.WeightedIndex(diceRolls);

// Generate a random 3D unit vector
Vector3 direction = random.UnitVector3();

// Generate a position within a cirle of radius = 5
Vector2 point = random.PointWithinCircle(5f);

// Generate a 32-character string with only alpha-numeric characters.
string str = random.AlphaNumericString(32);

// Make a generator which will produce random font styles.
var fontStyleGen = random.MakeEnumGenerator();
// Generate a font style
var style = fontStyleGen.Next();

// Pick a random warm color
var color = random.ColorWarm();
// Alter the color's hue randomly by no more than 1/10.
color = random.HueShift((ColorHSV)color, 0.1f);