Provides random element selection backed by a thread-safe source of random numbers.
Notable functionality provided by this package:
-
Random
extensions that generate a random floating-point number within a range:> using Vivelin.Luck; > new Random().Next(-100.0d, +100.0d) -86.09016276248272
-
A static, thread-safe way to generate numbers, based on the article Revisiting randomness by Jon Skeet:
> using Vivelin.Luck; > Rng.Next() 1284714155
-
An extension method on
IEnumerable<T>
that randomly selects an element, taking weights into account. Currently, this is only implemented for collections of types that implementIWeighted
, but this could be made optional in future versions.var collection = new[] { new WeightedValue(0.01), new WeightedValue(0.1), new WeightedValue(10), new WeightedValue(100) }; collection.Sample(); // More likely to return WeightedValue(100) than WeightedValue(0.01)