File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Assets/JCSUnity/Scripts/Util Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments