Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

Random

struct in Unity.Mathematics

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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.

Properties

Property Description
state The random number generator state. It should not be zero.

Constructors

Constructor Description
Random Constructs a Random instance with a given seed value. The seed must be non-zero.

Public Methods

Method Description
InitState Initialized 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
CreateFromIndex Constructs a Random instance with an index that gets hashed. The index must not be uint.MaxValue.