Skip to content

Commit

Permalink
JK
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTarantula committed Jul 24, 2018
1 parent 4e76e8c commit bbfce82
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 126 deletions.
8 changes: 0 additions & 8 deletions GamblersDice.Tests/FairDieTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public class FairDieTests
[Trait("Category", "Random")]
public void ConstructFairDie_Sides_Random() => Assert.IsType<FairDie>(new FairDie(_rnd, 6));

[Fact]
[Trait("Category", "Reference")]
public void ConstructFairDie_Ref() => Assert.IsType<FairDie>(new FairDie(ref _rnd));

[Fact]
[Trait("Category", "Reference")]
public void ConstructFairDie_Sides_Ref() => Assert.IsType<FairDie>(new FairDie(ref _rnd, 6));

[Theory]
[InlineData(6)]
[InlineData(20)]
Expand Down
75 changes: 0 additions & 75 deletions GamblersDice.Tests/GamblersDice.Tests.Ref.cs

This file was deleted.

13 changes: 2 additions & 11 deletions GamblersDice/FairDie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ public FairDie(int sides) : this(new Random(), sides) { }

/// <summary>Initializes a new fair die with a default of six sides. Bring your own <c>Random</c> object.</summary>
/// <param name="rnd"><c>Random</c> object to be used when rolling the die</param>
public FairDie(Random rnd) : this(ref rnd) { }
public FairDie(Random rnd) : this(rnd, 6) { }

/// <summary>Initializes a new fair die with the specified number of sides. Bring your own <c>Random</c> object.</summary>
/// <param name="rnd"><c>Random</c> object to be used when rolling the die.</param>
/// <param name="sides">Number of sides on the die.</param>
public FairDie(Random rnd, int sides) : this(ref rnd, sides) { }

/// <summary>Initializes a new fair die with a default of six sides using reference to a <c>Random</c> object.</summary>
/// <param name="rnd">Reference to <c>Random</c> object to be used when rolling the die.</param>
public FairDie(ref Random rnd) : this(ref rnd, 6) { }

/// <summary>Initializes a new fair die with the specified number of sides using reference to a <c>Random</c> object.</summary>
/// <param name="rnd">Reference to <c>Random</c> object to be used when rolling the die.</param>
/// <param name="sides">Number of sides on the die.</param>
public FairDie(ref Random rnd, int sides)
public FairDie(Random rnd, int sides)
{
_rnd = rnd;
_sides = sides;
Expand Down
2 changes: 1 addition & 1 deletion GamblersDice/GamblersDice.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageId>GamblersDice</PackageId>
<Title>Gambler's Dice</Title>
<Description>This set of dice follows the Gambler's fallacy. A C# port of https://github.com/xori/gamblers-dice</Description>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<Authors>Ryan Tauriainen</Authors>
<PackageLicenseUrl>https://github.com/MrTarantula/gamblers-dice/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/MrTarantula/gamblers-dice</RepositoryUrl>
Expand Down
25 changes: 6 additions & 19 deletions GamblersDice/GamblersDie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,13 @@ public GamblersDie(params int[] weights) : this(new Random(), weights) { }

/// <summary>Initializes a new gambler's die with a default of six sides. Bring your own <c>Random</c> object.</summary>
/// <param name="rnd"><c>Random</c> object to be used when rolling the die.</param>
public GamblersDie(Random rnd) : this(ref rnd) { }
public GamblersDie(Random rnd) : this(rnd, 6) { }

/// <summary>Initializes a new gambler's die with the specified number of sides. Bring your own <c>Random</c> object.</summary>
/// <param name="rnd"><c>Random</c> object to be used when rolling the die.</param>
/// <param name="size">Size of the die.</param>
public GamblersDie(Random rnd, int size) : this(ref rnd, size) { }

/// <summary>Initializes a new gambler's die with known weights. Bring your own <c>Random</c> object.</summary>
/// <param name="rnd"><c>Random</c> object to be used when rolling the die.</param>
/// <param name="weights">Pre-calculated weights of the sides of the die.</param>
public GamblersDie(Random rnd, params int[] weights) : this(ref rnd, weights) { }

/// <summary>Initializes a new gambler's die with a default of six sides using reference to a <c>Random</c> object.</summary>
/// <param name="rnd">Reference to <c>Random</c> object to be used when rolling the die.</param>
public GamblersDie(ref Random rnd) : this(ref rnd, 6) { }

/// <summary>Initializes a new gambler's die with the specified number of sides using reference to a <c>Random</c> object.</summary>
/// <param name="rnd">Reference to <c>Random</c> object to be used when rolling the die.</param>
/// <param name="size">Size of the die.</param>
public GamblersDie(ref Random rnd, int size) {
public GamblersDie(Random rnd, int size)
{
_rnd = rnd;
Weight = new int[size];

Expand All @@ -51,10 +38,10 @@ public GamblersDie(ref Random rnd, int size) {
}
}

/// <summary>Initializes a new gambler's die with known weights using reference to a <c>Random</c> object.</summary>
/// <param name="rnd">Reference to <c>Random</c> object to be used when rolling the die.</param>
/// <summary>Initializes a new gambler's die with known weights. Bring your own <c>Random</c> object.</summary>
/// <param name="rnd"><c>Random</c> object to be used when rolling the die.</param>
/// <param name="weights">Pre-calculated weights of the sides of the die.</param>
public GamblersDie(ref Random rnd, params int[] weights) : this(ref rnd, weights.Length)
public GamblersDie(Random rnd, params int[] weights) : this(rnd, weights.Length)
{
for (int i = 0; i < Weight.Length; i++)
{
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,4 @@ var die0 = new GamblersDie(rnd);
var die1 = new GamblersDie(rnd, 1, 1, 1, 7, 1, 1, 1);

var die2 = new FairDie(rnd, 20);
```

This can also be done with a reference to a `System.Random` object, but I'm currently not sure if there are any performance gains:

```C#
var rnd = new Random();

var die0 = new GamblersDie(ref rnd);

var die1 = new GamblersDie(ref rnd, 1, 1, 1, 7, 1, 1, 1);

var die2 = new FairDie(ref rnd, 20);
```

0 comments on commit bbfce82

Please sign in to comment.