Skip to content

Random Utilities Overview

What is RetroDev.Random?

RetroDev.Random is a comprehensive collection of randomization utilities for Unity. It extends Unity’s built-in random functionality with convenient methods for common randomization tasks that every game developer needs.

Get RetroDev.Random here:

Download Random →

The Problem It Solves

Common randomization tasks often require writing the same boilerplate code repeatedly:

Before RetroDev.Random:

// Get random element from array
int randomIndex = Random.Range(0, array.Length);
Color randomColor = array[randomIndex];
// Random position in bounds
float x = Random.Range(minBounds.x, maxBounds.x);
float y = Random.Range(minBounds.y, maxBounds.y);
Vector2 randomPos = new Vector2(x, y);

With RetroDev.Random:

Color randomColor = RandomUtil.RandomElement(array);
Vector2 randomPos = RandomUtil.RandomVector2D(minBounds, maxBounds);

Key Features

Comprehensive Coverage

From basic numbers to complex distributions, all the randomization you need in one place.

Unity-Friendly

Built-in support for Unity types: Vector2, Vector3, Color, Quaternion, AudioClip.

Statistical Methods

Includes normal distribution and weighted randomization for more realistic random behavior.

No Dependencies

Pure C# implementation that works everywhere Unity runs.

What RetroDev.Random Provides

Basic Randomization

  • Random booleans with configurable probability
  • Random integers and floats with ranges
  • Random elements from arrays and lists

Unity Types

  • Random colors (RGB + alpha)
  • Random 2D and 3D vectors within bounds
  • Random rotations (2D and 3D)
  • Random angles in radians

Advanced Features

  • Normal distribution (bell curve) randomization
  • Random points on unit circle
  • Random audio clip selection
  • Type-safe generic methods

Common Use Cases

Game Design:

// Random enemy spawn positions
Vector3 spawnPos = RandomUtil.RandomVector3D(minBounds, maxBounds);
// Random loot drops with probability
bool dropRareItem = RandomUtil.RandomBool(0.05f); // 5% chance
// Random enemy type
Enemy enemy = RandomUtil.RandomElement(enemyTypes);

Visual Effects:

// Random particle colors
Color particleColor = RandomUtil.RandomColor();
// Random rotation for debris
Quaternion rotation = RandomUtil.RandomRotation3D();

Audio:

// Random footstep sound
AudioClip footstep = RandomUtil.RandomAudioClip(footstepSounds);

When to Use RetroDev.Random

Perfect for:

  • Procedural generation
  • Loot and reward systems
  • Enemy AI variation
  • Visual and audio variety
  • Randomized level elements
  • Particle systems
  • Any game mechanic involving randomness

You might not need it if:

  • You only need basic Unity random numbers
  • You have specific random algorithms in place
  • You’re using a procedural generation framework

Understanding Probability

Some methods support probability parameters:

// 50% chance (default)
bool coinFlip = RandomUtil.RandomBool();
// 25% chance
bool rareEvent = RandomUtil.RandomBool(0.25f);
// 90% chance
bool commonEvent = RandomUtil.RandomBool(0.9f);

Normal Distribution

For more realistic randomization, use normal distribution:

// Values cluster around 0, rarely exceed ±2
float value = RandomUtil.RandomNormalDistribution(mean: 0f, stdDev: 1f);
// Great for:
// - Enemy accuracy (cluster around target with spread)
// - Damage variation (most hits near base damage)
// - Spawn distances (most spawns near center)

Getting Started

Ready to add better randomization to your game? Check out the Quick Start guide for detailed examples of every method.