Skip to content

Commit

Permalink
Merge pull request #74 from ZacharyPatten/dev-random-gen-improvements
Browse files Browse the repository at this point in the history
Dev random gen improvements
  • Loading branch information
ZacharyPatten committed Jan 29, 2021
2 parents f9a09a3 + 15709de commit b1e1e9a
Show file tree
Hide file tree
Showing 12 changed files with 2,559 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Examples/BasicsAndExtensions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ static void Main()
Console.WriteLine($" Random.NextChar('a', 'z'): {random.NextChar('a', 'z')}");
Console.WriteLine($" Random.NextDecimal(): {random.NextDecimal()}");
Console.WriteLine($" Random.NextTimeSpan(): {random.NextTimeSpan()}");
Console.WriteLine($" Random.Next(5, 0, 100, excluded: {{ 50, 51, 52, 53 }}): {string.Join(", ", random.Next(5, 0, 100, excluded: new[] { 50, 51, 52, 53 }))}");
Console.WriteLine($" Random.NextUnique(5, 0, 100): {string.Join(", ", random.NextUnique(5, 0, 100))}");
Console.WriteLine($" Random.NextUnique(5, 0, 100, excluded: {{ 50, 51, 52, 53 }}): {string.Join(", ", random.NextUnique(5, 0, 100, excluded: new[] { 50, 51, 52, 53 }))}");

var weightedNames = new (string Name, double Weight)[]
{
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,9 @@ decimal NextDecimal(this Random random);
DateTime DateTime(this Random random);
TimeSpan TimeSpan(this Random random);
long NextLong(this Random random);
IEnumerable<int> NextUnique(this Random random, int count, int minValue, int maxValue); // unique values
int[] Next(this Random random, int count, int minValue, int maxValue, Span<T> excluded); // with exclusions
int[] NextUnique(this Random random, int count, int minValue, int maxValue); // unique values
int[] NextUnique(this Random random, int count, int minValue, int maxValue, Span<T> excluded); // unique values with exclusions
T Next<T>(this Random random, IEnumerable<(T Value, double Weight)> pool); // weighted values
void Shuffle<T>(this Random random, T[] array); // randomize arrays
Expand Down

0 comments on commit b1e1e9a

Please sign in to comment.