Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Random

Random Number Generator based on xorshift. Designed for minimal state (32bits) to be easily embeddable into components. Core functionality is integer multiplication free to improve vectorization on less capable SIMD instruction sets.
Read time 2 minutesLast updated 4 days ago

Definition

public struct Random

Fields

Value

Description

stateThe random number generator state. It should not be zero.

Constructors

Constructor

Description

Random(System.UInt32)Constructs a Random instance with a given seed value. The seed must be non-zero.

Methods

Method

Description

InitStateInitialized the state of the Random instance with a given seed value. The seed must be non-zero.
NextBoolReturns a uniformly random bool value.
NextBool2Returns a uniformly random bool2 value.
NextBool3Returns a uniformly random bool3 value.
NextBool4Returns a uniformly random bool4 value.
NextDoubleReturns a uniformly random double value in the interval [0, 1).
NextDouble2Returns a uniformly random double2 value with all components in the interval [0, 1).
NextDouble2DirectionReturns a unit length double2 vector representing a uniformly random 2D direction.
NextDouble3Returns a uniformly random double3 value with all components in the interval [0, 1).
NextDouble3DirectionReturns a unit length double3 vector representing a uniformly random 3D direction.
NextDouble4Returns a uniformly random double4 value with all components in the interval [0, 1).
NextFloatReturns a uniformly random float value in the interval [0, 1).
NextFloat2Returns a uniformly random float2 value with all components in the interval [0, 1).
NextFloat2DirectionReturns a unit length float2 vector representing a uniformly random 2D direction.
NextFloat3Returns a uniformly random float3 value with all components in the interval [0, 1).
NextFloat3DirectionReturns a unit length float3 vector representing a uniformly random 3D direction.
NextFloat4Returns a uniformly random float4 value with all components in the interval [0, 1).
NextIntReturns a uniformly random int value in the interval [-2147483647, 2147483647].
NextInt2Returns a uniformly random int2 value with all components in the interval [-2147483647, 2147483647].
NextInt3Returns a uniformly random int3 value with all components in the interval [-2147483647, 2147483647].
NextInt4Returns a uniformly random int4 value with all components in the interval [-2147483647, 2147483647].
NextQuaternionRotationReturns a unit length quaternion representing a uniformly 3D rotation.
NextUIntReturns a uniformly random uint value in the interval [0, 4294967294].
NextUInt2Returns a uniformly random uint2 value with all components in the interval [0, 4294967294].
NextUInt3Returns a uniformly random uint3 value with all components in the interval [0, 4294967294].
NextUInt4Returns a uniformly random uint4 value with all components in the interval [0, 4294967294].

Static Methods

Method

Description

CreateFromIndexConstructs a Random instance with an index that gets hashed. The index must not be uint.MaxValue.