Table of Contents

Class RandomExtensions

Namespace
Stride.CommunityToolkit.Mathematics
Assembly
Stride.CommunityToolkit.dll

Helper extension methods for Random tailored for gameplay and procedural content scenarios.

public static class RandomExtensions
Inheritance
RandomExtensions

Remarks

Provides convenience APIs for:

All methods validate the Random instance and use single-precision math to align with Stride's Vector2, Vector3, and Color types.

Methods

NextColor(Random)

Generates a random color.

public static Color NextColor(this Random random)

Parameters

random Random

An instance of Random.

Returns

Color

A random color. Alpha is set to 255.

Exceptions

ArgumentNullException

If the random argument is null.

NextDirection2D(Random)

Generates a random normalized 2D direction vector.

public static Vector2 NextDirection2D(this Random random)

Parameters

random Random

An instance of Random.

Returns

Vector2

A unit-length (or zero) direction vector in the XY plane.

Exceptions

ArgumentNullException

If the random argument is null.

NextDirection3D(Random)

Generates a random normalized 3D direction vector.

public static Vector3 NextDirection3D(this Random random)

Parameters

random Random

An instance of Random.

Returns

Vector3

A unit-length (or zero) direction vector in 3D space.

Exceptions

ArgumentNullException

If the random argument is null.

NextPoint(Random, BoundingBox)

Generates a random point in 3D space within the specified region.

public static Vector3 NextPoint(this Random random, BoundingBox region)

Parameters

random Random

An instance of Random.

region BoundingBox

A 3D region in which point is generated.

Returns

Vector3

A random point whose X/Y/Z components lie within region's bounds.

Exceptions

ArgumentNullException

If the random argument is null.

NextPoint(Random, RectangleF)

Generates a random point in 2D space within the specified region.

public static Vector2 NextPoint(this Random random, RectangleF region)

Parameters

random Random

An instance of Random.

region RectangleF

A 2D region in which point is generated.

Returns

Vector2

A random point in 2D space within the specified region.

Exceptions

ArgumentNullException

If the random argument is null.

NextSingle(Random)

Generates a random float.

public static float NextSingle(this Random random)

Parameters

random Random

An instance of Random.

Returns

float

A random float.

Exceptions

ArgumentNullException

If the random argument is null.

PointInACircle(Random, float)

Generates a random point uniformly distributed inside a circle of the given radius.

public static Vector2 PointInACircle(this Random random, float radius = 1)

Parameters

random Random

An instance of Random.

radius float

Radius of circle. Default 1.0f.

Returns

Vector2

A random point whose distance from the origin is <= radius.

Exceptions

ArgumentNullException

If the random argument is null.