Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
[SharpDX] Fix bug so that MathUtil.NextLong can produce the specified…
Browse files Browse the repository at this point in the history
… max value

Previously, the largest value it could ever return was max - 1.

This also eliminates a divide by zero issue that happened when when max == min.
  • Loading branch information
shoelzer committed Sep 4, 2013
1 parent 1267028 commit b558d7b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/SharpDX/MathUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public static long NextLong(this Random random, long min, long max)
random.NextBytes(buf);
long longRand = BitConverter.ToInt64(buf, 0);

return (Math.Abs(longRand % (max - min)) + min);
return (Math.Abs(longRand % (max - min + 1)) + min);
}

/// <summary>
Expand Down Expand Up @@ -654,7 +654,7 @@ public static long NextLong(Random random, long min, long max)
random.NextBytes(buf);
long longRand = BitConverter.ToInt64(buf, 0);

return (Math.Abs(longRand % (max - min)) + min);
return (Math.Abs(longRand % (max - min + 1)) + min);
}

/// <summary>
Expand Down

0 comments on commit b558d7b

Please sign in to comment.