Skip to content
/ Luck Public

Provides random element selection backed by a thread-safe source of random numbers.

Notifications You must be signed in to change notification settings

Vivelin/Luck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vivelin.Luck

Provides random element selection backed by a thread-safe source of random numbers.

Build status NuGet

Usage

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 implement IWeighted, 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)

About

Provides random element selection backed by a thread-safe source of random numbers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages