aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/math/random.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-11 11:29:07 +0800
committerchai <chaifix@163.com>2020-02-11 11:29:07 +0800
commit160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch)
treeabe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/math/random.cpp
parente095043485d1d298571af6d9eca7f0db9009ea7a (diff)
*修改 tab大小HEADmaster
Diffstat (limited to 'src/libjin/math/random.cpp')
-rw-r--r--src/libjin/math/random.cpp94
1 files changed, 47 insertions, 47 deletions
diff --git a/src/libjin/math/random.cpp b/src/libjin/math/random.cpp
index 5f3b28c..288f6c8 100644
--- a/src/libjin/math/random.cpp
+++ b/src/libjin/math/random.cpp
@@ -4,51 +4,51 @@
namespace JinEngine
{
- namespace Math
- {
-
- RandomGenerator::RandomGenerator(uint32 seed)
- : mSeed(seed)
- {
- }
-
- uint32 RandomGenerator::rand()
- {
- unsigned int next = mSeed;
- uint32 result;
-
- next *= 1103515245;
- next += 12345;
- result = (unsigned int)(next / 65536) % 2048;
-
- next *= 1103515245;
- next += 12345;
- result <<= 10;
- result ^= (unsigned int)(next / 65536) % 1024;
-
- next *= 1103515245;
- next += 12345;
- result <<= 10;
- result ^= (unsigned int)(next / 65536) % 1024;
-
- mSeed = next;
-
- return result;
- }
-
- uint32 RandomGenerator::rand(uint32 min, uint32 max)
- {
- uint32 n = rand();
- return n % (max - min + 1) + min;
- }
-
- float RandomGenerator::randf(float min, float max, int ac)
- {
- float floor = 0, ceil = max + reverse<float>(min);
- uint32 a = pow(10.f, ac);
- uint32 n = rand(floor*a, ceil*a);
- return (float)n / a + min;
- }
-
- }
+ namespace Math
+ {
+
+ RandomGenerator::RandomGenerator(uint32 seed)
+ : mSeed(seed)
+ {
+ }
+
+ uint32 RandomGenerator::rand()
+ {
+ unsigned int next = mSeed;
+ uint32 result;
+
+ next *= 1103515245;
+ next += 12345;
+ result = (unsigned int)(next / 65536) % 2048;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int)(next / 65536) % 1024;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int)(next / 65536) % 1024;
+
+ mSeed = next;
+
+ return result;
+ }
+
+ uint32 RandomGenerator::rand(uint32 min, uint32 max)
+ {
+ uint32 n = rand();
+ return n % (max - min + 1) + min;
+ }
+
+ float RandomGenerator::randf(float min, float max, int ac)
+ {
+ float floor = 0, ceil = max + reverse<float>(min);
+ uint32 a = pow(10.f, ac);
+ uint32 n = rand(floor*a, ceil*a);
+ return (float)n / a + min;
+ }
+
+ }
} \ No newline at end of file