Skip to content

Commit 5b59e89

Browse files
committed
chore: rand long
1 parent ecacd8b commit 5b59e89

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Random.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public static class JCS_Random
1919
{
2020
/* Variables */
2121

22+
private static System.Random SYS_RAND = new System.Random();
23+
2224
/* Setter & Getter */
2325

2426
/* Functions */
@@ -49,6 +51,22 @@ public static float Range(float min, float max)
4951
{
5052
return Random.Range(min, max);
5153
}
54+
public static long Range(long min, long max)
55+
{
56+
long r = max - min;
57+
58+
var buf = new byte[8];
59+
SYS_RAND.NextBytes(buf);
60+
long v = System.BitConverter.ToInt64(buf, 0);
61+
62+
return min + System.Math.Abs(v % (r + 1));
63+
}
64+
public static double Range(double min, double max)
65+
{
66+
double v = SYS_RAND.NextDouble();
67+
68+
return min + (v * (max - min));
69+
}
5270

5371
/// <summary>
5472
/// Return normal random range and cover the max value.

0 commit comments

Comments
 (0)