/FateRandom

Different extensions to random number generators

Primary LanguageC#MIT LicenseMIT

FateRandom

FateRandom is wrappers and extensions for random number generator.

Main class Fate and its interface for mocks and injections IFate have the following list of methods:

  • float NextFloat()
  • float NextFloat(float max)
  • int NextInt(int max)
  • float NextAngle()
  • int Range(int min, int max)
  • float Range(float min, float max)
  • double Range(double min, double max)
  • bool Chance(float percent)
  • bool Chance(int value)
  • T Choose(T first, T second)
  • T Choose(T first, T second, T third)
  • T Choose(T first, T second, T third, T fourth)
  • T Choose(params T[] list)
  • T Choose(IList list)
  • string GenerateString(int size = 38)
  • void Shuffle(IList list)
  • void RandomItems(IList source, List destination, int itemCount)

To make results more predictable for tests it has a few different random number generations:

  • DefaultRandomGenerator - Uses System.Random underneath
  • KnownDataRandomGenerator - Initialized with array of values that is returned in a sequence
  • PregeneratedRandomGenerator - Something in the middle of the above - a predefined amount of numbers generated by System.Random and stored in memory. This one can be used to save current state of random number generator, so it will generate the same sequence after load.

Credits

  • Nez - GitHub stars - 2D game engine.