diff options
author | chai <chaifix@163.com> | 2018-11-18 22:32:55 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-11-18 22:32:55 +0800 |
commit | fc7b4579e49aaeecc81919e247e03f68bd5abfd4 (patch) | |
tree | 6547b8c7d3632591358267d06006eddc53216105 /src/libjin/Math/je_random.cpp | |
parent | 3905924fc35f92e5092576c3f6e8fc5db7588cde (diff) |
*粒子系统
Diffstat (limited to 'src/libjin/Math/je_random.cpp')
-rw-r--r-- | src/libjin/Math/je_random.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/libjin/Math/je_random.cpp b/src/libjin/Math/je_random.cpp index 983fa36..216fd79 100644 --- a/src/libjin/Math/je_random.cpp +++ b/src/libjin/Math/je_random.cpp @@ -1,3 +1,4 @@ +#include <math.h> #include "je_random.h" namespace JinEngine @@ -5,9 +6,47 @@ namespace JinEngine namespace Math { - RandomGenerator::RandomGenerator() + 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) + { + uint32 a = pow(10.f, ac); + uint32 n = rand(min*a, max*a); + return (float)n / a; + } + } }
\ No newline at end of file |