跳到主要内容

Class Random

Provides random functions. this is a high-level wrapper for UnityEngine.Random.

Properties

normalDistribution

Built-in normal distribution randomizer.

public static Randomizer normalDistribution { get; }

Methods

SetSeed(int randomSeed)

Set a random seed.

public static void SetSeed(int randomSeed)

SetState(State randomState)

Set a random seed (Represented by UnityEngine.Random.state).

public static void SetState(State randomState)

GetState()

Get current random seed (Represented by UnityEngine.Random.state).

public static State GetState()

Bool()

Returns a random System.Boolean value.

public static bool Bool()

Range(int baseValue, int interval)

Returns a random int value in the range [baseValue-interval, baseValue+interval].

public static int Range(int baseValue, int interval)

Int(int max)

Returns a random int value in the range [0, max).

public static int Int(int max)

Int(int min, int max)

Returns a random int value in the range [min, max).

public static int Int(int min, int max)

Int(Vector2Int range)

Returns a random int value in the range [range.x, range.y].

public static int Int(Vector2Int range)

GetValueByProbability(int min, int max, float probability)

Returns a value within the inclusive range [min, max] based on a probability.

If probability is 1, returns max;

If probability is 0, returns min;

If probability is between 0 and 1, uses a "roulette-wheel" style of incrementing from min toward max based on that probability.

public static int GetValueByProbability(int min, int max, float probability)

Pick(int min, int max, int count)

Returns count random numbers from the interval [min, max].

public static IEnumerable<int> Pick(int min, int max, int count)

Pick<T>(T object1, T object2)

Randomly select one from object1 and object2.

public static T Pick<T>(T object1, T object2)

Shuffle<T>(IList<T> list)

Shuffle the elements of a list. This method ensures that each element is no longer in its original position.

public static void Shuffle<T>(IList<T> list)

Vector3(float min, float max)

Returns a random UnityEngine.Vector3.

public static Vector3 Vector3(float min, float max)

Vector3(Vector3 min, Vector3 max)

Returns a random UnityEngine.Vector3.

public static Vector3 Vector3(Vector3 min, Vector3 max)

Vector2(float min, float max)

Returns a random UnityEngine.Vector2.

public static Vector2 Vector2(float min, float max)

Direction()

Returns a random 3D direction.

public static Vector3 Direction()

Direction(Vector3 startDirection, float maxAngle, Vector3 axis)

public static Vector3 Direction(Vector3 startDirection, float maxAngle, Vector3 axis)

Direction(Vector3 startDirection, Vector3 endDirection, [bool safe = true])

Returns a random 3D direction between startDirection and endDirection.

public static Vector3 Direction(Vector3 startDirection, Vector3 endDirection, [bool safe = true])

Direction2D()

Returns a random 2D direction.

public static Vector2 Direction2D()

Direction2D(Vector2 direction, float maxAngle, [bool safe = true])

Returns a random 2D direction by rotating direction by a random angle within the range [-maxAngle, +maxAngle].

public static Vector2 Direction2D(Vector2 direction, float maxAngle, [bool safe = true])

Direction2D(Vector2 startDirection, Vector2 endDirection, [bool safe = true])

Returns a random 2D direction between startDirection and endDirection.

public static Vector2 Direction2D(Vector2 startDirection, Vector2 endDirection, [bool safe = true])

Range(float baseValue, float interval)

Returns a random float value in the range [baseValue-interval, baseValue+interval].

public static float Range(float baseValue, float interval)

Float01()

Returns a random float value in the range [0, 1].

public static float Float01()

Float(float max)

Returns a random float value in the range [0, max].

public static float Float(float max)

Float(float min, float max)

Returns a random float value in the range [min, max].

public static float Float(float min, float max)

Float(Vector2 range)

Returns a random float value in the range [range.x, range.y].

public static float Float(Vector2 range)

FloatNormalized()

Returns a random float value in the range [-1, 1].

public static float FloatNormalized()

PerlinNoise(float x)

Returns the Perlin noise in the range [0, 1] based on the sample point x.

public static float PerlinNoise(float x)

PerlinNoiseNormalized(float x)

Returns the Perlin noise in the range [-1, 1] based on the sample point x.

public static float PerlinNoiseNormalized(float x)

RandomPointInViewFrustum(Camera camera)

Returns a random position in the camera view frustum.

public static Vector3 RandomPointInViewFrustum(Camera camera)