-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into splatsave
- Loading branch information
Showing
4 changed files
with
162 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
#include "SeedRand.h" | ||
|
||
SeedRand::SeedRand(uint32_t seed = 0) { | ||
mSeed = seed; | ||
uint32_t priv_seed = seed; | ||
for (int i = 0; i < 4; i++) { | ||
mState[i] = | ||
(uint32_t)(0x6C078965 * (priv_seed ^ (priv_seed >> 30)) + i + 1); | ||
priv_seed = mState[i]; | ||
mState[i] = (uint32_t)(0x6C078965 * (seed ^ (seed >> 30)) + i + 1); | ||
seed = mState[i]; | ||
} | ||
} | ||
|
||
SeedRand::SeedRand(uint32_t seed, std::array<uint32_t, 4> state) { | ||
mSeed = seed; | ||
SeedRand::SeedRand(std::array<uint32_t, 4> state) { | ||
mState = state; | ||
} | ||
|
||
uint32_t SeedRand::getU32() { | ||
uint32_t a = mState[0] ^ (mState[0] << 11); | ||
uint32_t b = mState[3]; | ||
uint32_t c = a ^ (a >> 8) ^ b ^ (b >> 19); | ||
mState[0] = mState[1]; | ||
mState[1] = mState[2]; | ||
mState[2] = mState[3]; | ||
for (int i = 0; i < 3; i++) | ||
mState[i] = mState[i + 1]; | ||
mState[3] = c; | ||
return c; | ||
} | ||
|
||
uint64_t SeedRand::getU64() { | ||
uint32_t a = mState[1]; | ||
uint32_t b = mState[0] ^ (mState[0] << 11); | ||
uint32_t c = mState[3]; | ||
mState[0] = mState[2]; | ||
mState[1] = c; | ||
uint32_t d = b ^ (b >> 8) ^ c; | ||
uint32_t e = d ^ (c >> 19); | ||
uint32_t f = a ^ (a << 11) ^ ((a ^ (a << 11)) >> 8) ^ e ^ (d >> 19); | ||
mState[2] = e; | ||
mState[3] = f; | ||
return f | ((uint64_t)e << 32); | ||
} | ||
|
||
std::array<uint32_t, 4> SeedRand::getContext() { | ||
return mState; | ||
} |
Oops, something went wrong.