diff options
author | Sven Gothel <[email protected]> | 2015-03-28 01:43:35 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-03-28 01:43:35 +0100 |
commit | 4207f9c279e832e3afcb3f5fc6cd8d84cb4cfe4c (patch) | |
tree | cf3671058d55b47ab6cb6f36f369928606137628 /LibOVRKernel/Src/Kernel/OVR_Rand.cpp | |
parent | c29cd1a2fbff6282bab956ad61661ac9d48c4e6e (diff) |
Bump OculusVR RIFT SDK to 0.5.0.1vanilla_0.5.0.1
Diffstat (limited to 'LibOVRKernel/Src/Kernel/OVR_Rand.cpp')
-rw-r--r-- | LibOVRKernel/Src/Kernel/OVR_Rand.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/LibOVRKernel/Src/Kernel/OVR_Rand.cpp b/LibOVRKernel/Src/Kernel/OVR_Rand.cpp new file mode 100644 index 0000000..3d6f50e --- /dev/null +++ b/LibOVRKernel/Src/Kernel/OVR_Rand.cpp @@ -0,0 +1,79 @@ +/************************************************************************** + +Filename : OVR_Rand.cpp +Content : Random number generator +Created : Aug 28, 2014 +Author : Chris Taylor + +Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. + +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +http://www.oculusvr.com/licenses/LICENSE-3.2 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Rand.h" +#include "OVR_Timer.h" + +namespace OVR { + + +void RandomNumberGenerator::SeedRandom() +{ + uint64_t seed = Timer::GetTicksNanos(); + + uint32_t x = (uint32_t)seed, y = (uint32_t)(seed >> 32); + + Seed(x, y); +} + +void RandomNumberGenerator::Seed(uint32_t x, uint32_t y) +{ + // Based on the mixing functions of MurmurHash3 + static const uint64_t C1 = 0xff51afd7ed558ccdULL; + static const uint64_t C2 = 0xc4ceb9fe1a85ec53ULL; + + x += y; + y += x; + + uint64_t seed_x = 0x9368e53c2f6af274ULL ^ x; + uint64_t seed_y = 0x586dcd208f7cd3fdULL ^ y; + + seed_x *= C1; + seed_x ^= seed_x >> 33; + seed_x *= C2; + seed_x ^= seed_x >> 33; + + seed_y *= C1; + seed_y ^= seed_y >> 33; + seed_y *= C2; + seed_y ^= seed_y >> 33; + + Rx = seed_x; + Ry = seed_y; + + // Inlined Next(): Discard first output + + Rx = (uint64_t)0xfffd21a7 * (uint32_t)Rx + (uint32_t)(Rx >> 32); + Ry = (uint64_t)0xfffd1361 * (uint32_t)Ry + (uint32_t)(Ry >> 32); + + // Throw away any saved RandN() state + HaveRandN = false; + + Seeded = true; +} + + +} // namespace OVR |