Skip to content

Commit

Permalink
Added code comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Konard committed Aug 11, 2019
1 parent f58b4ac commit 5b2c0b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions RandomExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@ namespace Platform.Random
{
public static class RandomExtensions
{
/// <summary>
/// Returns a random 64-bit unsigned integer that is greater than or equal to ulong.MinValue, and less than or equal to ulong.MaxValue.
/// Возвращает случайное 64-разрядное целое число без знака, которое больше или равно ulong.MinValue и меньше или равно ulong.MaxValue.
/// </summary>
/// <param name="rnd">A pseudo-random number generator. Генератор псевдослучайных чисел.</param>
/// <returns>A 64-bit unsigned integer that is greater than or equal to ulong.MinValue, and less than or equal to ulong.MaxValue. 64-разрядное целое число без знака, которое больше или равно ulong.MinValue и меньше или равно ulong.MaxValue.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong NextUInt64(this System.Random rnd) => rnd.NextUInt64(new Range<ulong>(ulong.MinValue, ulong.MaxValue));

/// <summary>
/// Returns a random 64-bit unsigned integer that is greater than or equal to minimum of specified range, and less than or equal to maximum of specified range.
/// Возвращает случайное 64-разрядное целое число без знака, которое больше или равно минимуму указанного диапазона и меньше или равно максимуму указанного диапазона.
/// </summary>
/// <param name="rnd">A pseudo-random number generator. Генератор псевдослучайных чисел.</param>
/// <param name="range">The range of possible values. Диапазон возможных значений.</param>
/// <returns>A 64-bit unsigned integer that is greater than or equal to the minimum of specified range, and less than or equal to the maximum of the specified range. 64-разрядное целое число без знака, которое больше или равно минимуму указанного диапазона и меньше или равно максимуму указанного диапазона.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong NextUInt64(this System.Random rnd, Range<ulong> range) => (ulong)(rnd.NextDouble() * (range.Maximum - range.Minimum)) + range.Minimum;

/// <summary>
/// Return a random boolean value.
/// Возвращает случайное булево значение.
/// </summary>
/// <param name="rnd">A pseudo-random number generator. Генератор псевдослучайных чисел.</param>
/// <returns>A random boolean value. Случайное булево значение.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool NextBoolean(this System.Random rnd) => rnd.Next(2) == 1;
}
Expand Down
4 changes: 4 additions & 0 deletions RandomHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
{
public static class RandomHelpers
{
/// <summary>
/// Returns the pseudorandom number generator that is using the time of the first access to this field as seed.
/// Возвращает генератор псевдослучайных чисел использующий в качестве seed время первого обращения к этому полю.
/// </summary>
public static readonly System.Random Default = new System.Random(System.DateTime.UtcNow.Ticks.GetHashCode());
}
}

0 comments on commit 5b2c0b2

Please sign in to comment.