Table of Contents

Interface

Interface defining a random number generation system with customizable index and seed types.

public interface IRandomFunction<TIndex, TSeed> where TIndex : struct where TSeed : struct

Type Parameters

TIndex

The type representing the current position or index of the generator. Must be a value type.

TSeed

The type representing the initial seed value for the generator. Must be a value type.

Extension Methods

Properties

Bool

Represents a boolean value generated based on a random function. Utilizes an underlying random noise function to produce true or false with an equal probability of approximately 50%.

bool Bool { get; }

Property Value

bool

Byte

Retrieves a randomly generated byte value derived from the internal state of the random number generator. This property utilizes the random function's mechanism to produce a uniformly distributed 8-bit unsigned integer value.

byte Byte { get; }

Property Value

byte

Direction2D

Represents a randomly generated 2D directional vector with normalized length. This property utilizes noise-based randomness to produce a direction that is evenly distributed within the unit circle in a 2D space.

float2 Direction2D { get; }

Property Value

float2

Direction3D

Provides a random three-dimensional unit vector (float3) based on the current state of the random number generator. This allows the generation of a direction in 3D space uniformly distributed over the unit sphere.

float3 Direction3D { get; }

Property Value

float3

Direction4D

Represents a randomly generated 4-dimensional directional vector. Provides a normalized float4 value, ensuring each direction is uniformly distributed across the 4D space.

float4 Direction4D { get; }

Property Value

float4

InsideUnitCircle

Generates a random two-dimensional point within the unit circle. The generated point's x and y coordinates are uniformly distributed, and the point lies inside or on the boundary of a circle with a radius of 1.

float2 InsideUnitCircle { get; }

Property Value

float2

InsideUnitSphere

Represents a random point within a unit sphere, where the sphere is centered at the origin and has a radius of 1. The distribution of points ensures uniformity within the sphere's volume, providing a balanced random sample.

float3 InsideUnitSphere { get; }

Property Value

float3

OnUnitSphere

Generates a random point uniformly distributed on the surface of a unit sphere. Useful for scenarios requiring random direction vectors, such as in simulations or graphical applications involving spherical distributions.

float3 OnUnitSphere { get; }

Property Value

float3

Position

Tracks the current position or state within the sequence of generated random values. Used to ensure deterministic progression of values based on the current state.

TIndex Position { get; set; }

Property Value

TIndex

Rotation

Represents a randomly generated quaternion rotation. Provides an evenly distributed random rotation, useful for applications involving 3D rotational randomness such as randomized orientations or procedural generation.

quaternion Rotation { get; }

Property Value

quaternion

RotationUniform

Generates a uniformly distributed random quaternion representing a random rotation. Useful for applications requiring unbiased rotational randomness, such as procedural orientation generation.

quaternion RotationUniform { get; }

Property Value

quaternion

Seed

Represents the seed value used to initialize the random number generator. Serves as the basis for ensuring deterministic random value generation, allowing reproducible sequences of random numbers.

TSeed Seed { get; set; }

Property Value

TSeed

Uint128

ulong2 Uint128 { get; }

Property Value

ulong2

Uint16

Generates a 16-bit unsigned integer (ushort) pseudo-random value. Useful for scenarios where a smaller random number with reduced memory footprint is sufficient. The value is derived from a higher precision random number by shifting its bits.

ushort Uint16 { get; }

Property Value

ushort

Uint32

Provides a 32-bit unsigned integer value representing a random or pseudo-random result. Typically employed in generating random values for various computational purposes. Derived using a noise function based on the current state and position of the generator.

uint Uint32 { get; }

Property Value

uint

Uint64

Generates a 64-bit unsigned integer value derived from the current state of the random number generator. Utilized for scenarios where high-precision randomness is required or larger numeric ranges are involved.

ulong Uint64 { get; }

Property Value

ulong

Value

Provides a floating-point value between 0 and 1, representing a normalized random value generated based on the current state of the random number generator. This value is derived using the associated random function and noise function.

float Value { get; }

Property Value

float

Methods

Chance(float)

Determines whether a chance-based event occurs based on the given probability.

bool Chance(float probabilityOfTrue)

Parameters

probabilityOfTrue float

A floating-point value between 0.0 and 1.0 representing the probability of returning true.

Returns

bool

True if the event occurs based on the provided probability, otherwise false.

Float2(float, float, float, float)

Generates a random 2-dimensional vector with each component constrained within specified ranges.

float2 Float2(float minX = -3.4028235E+38, float maxX = 3.4028235E+38, float minY = -3.4028235E+38, float maxY = 3.4028235E+38)

Parameters

minX float

The minimum value for the X component of the generated vector. Default is float.MinValue.

maxX float

The maximum value for the X component of the generated vector. Default is float.MaxValue.

minY float

The minimum value for the Y component of the generated vector. Default is float.MinValue.

maxY float

The maximum value for the Y component of the generated vector. Default is float.MaxValue.

Returns

float2

A float2 representing a random 2D vector within the specified ranges.

Float3(float, float, float, float, float, float)

Generates a random float3 value with each component constrained within the defined ranges for X, Y, and Z axes.

float3 Float3(float minX = -3.4028235E+38, float maxX = 3.4028235E+38, float minY = -3.4028235E+38, float maxY = 3.4028235E+38, float minZ = -3.4028235E+38, float maxZ = 3.4028235E+38)

Parameters

minX float

The minimum value for the X-axis.

maxX float

The maximum value for the X-axis.

minY float

The minimum value for the Y-axis.

maxY float

The maximum value for the Y-axis.

minZ float

The minimum value for the Z-axis.

maxZ float

The maximum value for the Z-axis.

Returns

float3

A float3 structure representing a position with randomly generated X, Y, and Z coordinates within the specified ranges.

Float4(float, float, float, float, float, float, float, float)

Generates a 4D vector (float4), where each component is randomly selected within specified ranges.

float4 Float4(float minX = -3.4028235E+38, float maxX = 3.4028235E+38, float minY = -3.4028235E+38, float maxY = 3.4028235E+38, float minZ = -3.4028235E+38, float maxZ = 3.4028235E+38, float minW = -3.4028235E+38, float maxW = 3.4028235E+38)

Parameters

minX float

The minimum value for the X component of the vector. Defaults to float.MinValue.

maxX float

The maximum value for the X component of the vector. Defaults to float.MaxValue.

minY float

The minimum value for the Y component of the vector. Defaults to float.MinValue.

maxY float

The maximum value for the Y component of the vector. Defaults to float.MaxValue.

minZ float

The minimum value for the Z component of the vector. Defaults to float.MinValue.

maxZ float

The maximum value for the Z component of the vector. Defaults to float.MaxValue.

minW float

The minimum value for the W component of the vector. Defaults to float.MinValue.

maxW float

The maximum value for the W component of the vector. Defaults to float.MaxValue.

Returns

float4

A float4 vector where each component is within the specified minimum and maximum range.

Perlin(float, float)

Generates a Perlin noise value based on the provided 2D coordinates, seed, and noise type. The noise value is computed by hashing the corners of the surrounding grid and applying interpolation.

float Perlin(float x, float y)

Parameters

x float

The X coordinate (continuous) used for generating the noise value.

y float

The Y coordinate (continuous) used for generating the noise value.

Returns

float

Perlin(float, float, float)

Generates a Perlin noise value based on the input coordinates and a specified seed. This method calculates smooth noise by blending integer-based deterministic noise values at each corner of the cube enclosing the input coordinates.

float Perlin(float x, float y, float z)

Parameters

x float

The x-coordinate of the noise input.

y float

The y-coordinate of the noise input.

z float

The z-coordinate of the noise input.

Returns

float

A single-precision floating-point value representing the Perlin noise at the given coordinates.

Range(int, int)

Generates a random integer within a specified range using the Squirrel Noise RNG algorithm.

int Range(int minInclusive, int maxExclusive)

Parameters

minInclusive int

The minimum value (inclusive) of the desired random integer range.

maxExclusive int

The maximum value (exclusive) of the desired random integer range.

Returns

int

A random integer between minInclusive (inclusive) and maxExclusive (exclusive).

Range(float, float)

Generates a uniformly random floating-point number within the specified range using Squirrel Noise.

float Range(float minInclusive, float maxInclusive)

Parameters

minInclusive float

The lower bound of the range (inclusive).

maxInclusive float

The upper bound of the range (inclusive).

Returns

float

A random float value between minInclusive and maxInclusive.

ResetSeed(TSeed, TIndex)

Resets the internal state of the random number generator to the specified seed and position.

void ResetSeed(TSeed seed, TIndex position)

Parameters

seed TSeed

The new seed value to initialize the random number generator.

position TIndex

The starting position for generating random values. Defaults to 0.