Rand
namespace Griff;
public static class RandRandom numbers for gameplay: spawn points, loot rolls, a little variety in juice. They’re the running game’s own: each game has its numbers (two games on one thread don’t share them), they go into its rewind snapshots, and a rewound game draws the same numbers again. Call Seed to make a run repeatable (handy for tests and daily challenges).
Properties
Section titled “Properties”public static float Value { get; }A number from 0 up to (not including) 1.
Methods
Section titled “Methods”Chance
Section titled “Chance”public static bool Chance(float probability)True with the given probability: 0.25 is true about a quarter of the time.
public static Color Color()A color with each of red, green and blue picked at random; fully opaque.
Direction
Section titled “Direction”public static Vector2 Direction()A direction of length 1, pointing anywhere.
InsideCircle
Section titled “InsideCircle”public static Vector2 InsideCircle(float radius = 1f)A point inside a circle of radius around the origin, spread evenly over its area.
public static T? Pick<T>(IReadOnlyList<T> items)One of items, chosen evenly.
public static float Range(float min, float max)A number from min up to max.
public static int Range(int min, int maxExclusive)A whole number from min up to, but not including, maxExclusive.
public static void Seed(int seed)Restarts the sequence so the same calls give the same numbers.
In a game (a script’s Start, say) it restarts that game’s numbers. Outside one (a test, a tool), it restarts the numbers drawn there, and a game that takes its first step on the same thread after it starts from them: Rand.Seed(5) before a new game’s first step makes it play the same every time. The scripts of a crowd (see CrowdAttribute) each get numbers of their own, from a seed the crowd takes from the game’s each time it runs: the same calls still give the same numbers, however many cores share the crowd.
public static int Sign()-1 or 1, evenly.