-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRandom.cs
46 lines (41 loc) · 1.92 KB
/
Random.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Copyright 2023 Kostasel
//See license.txt for license details
using System.Threading;
namespace EncryptedTypes
{
internal readonly ref struct Random
{
private static readonly System.Random rnd = new (System.DateTime.Now.Millisecond);
/// <summary>
/// Calculates a random number from 1 to 1000.
/// </summary>
/// <param name="result">A reference to a variable to write the result</param>
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
internal static void GetNew(ref int result)
{
Interlocked.Exchange(ref result, rnd.Next(1, 1000));
}
/// <summary>
/// Calculates a random number from min to max.
/// </summary>
/// <param name="min">A reference to a variable containing the lowest random number.</param>
/// <param name="max">A reference to a variable containing the highest random number.</param>
/// <param name="result">A reference to a variable to write the result</param>
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
internal static void GetNew(ref int min, ref int max, ref int result)
{
Interlocked.Exchange(ref result, rnd.Next(min, max));
}
/// <summary>
/// Calculates a random number from min to max.
/// </summary>
/// <param name="min">The lowest random number</param>
/// <param name="max">The highest random number</param>
/// <param name="result">A variable to write the result</param>
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
internal static void GetNew(int min, int max, ref int result)
{
Interlocked.Exchange(ref result, rnd.Next(min, max));
}
}
}