aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVRKernel/Src/Kernel/OVR_Rand.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-28 02:08:11 +0100
committerSven Gothel <[email protected]>2015-03-28 02:08:11 +0100
commit450aa6f7df9e67dd256b86f94e65eaf707032aad (patch)
tree04aa207d84ddc8ca246d2573aaaf756b3ce8a0b5 /LibOVRKernel/Src/Kernel/OVR_Rand.cpp
parent3c7b8a17e907f4ef2afd9f77db566a3f6179cbe4 (diff)
parent4207f9c279e832e3afcb3f5fc6cd8d84cb4cfe4c (diff)
Merge branch 'vanilla_0.5.0.1' into jogamp_0.5.0.1
Conflicts: LibOVR/Include/OVR_CAPI_0_5_0.h LibOVR/Src/CAPI/CAPI_HMDState.cpp LibOVR/Src/Displays/OVR_Win32_Dxgi_Display.h LibOVR/Src/Kernel/OVR_System.cpp LibOVR/Src/OVR_CAPI.cpp LibOVR/Src/OVR_Profile.cpp LibOVRKernel/Src/Kernel/OVR_ThreadsWinAPI.cpp LibOVRKernel/Src/Kernel/OVR_Types.h
Diffstat (limited to 'LibOVRKernel/Src/Kernel/OVR_Rand.cpp')
-rw-r--r--LibOVRKernel/Src/Kernel/OVR_Rand.cpp79
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