// ******************************************************************* // (C) Copyright 2013 Leiden Institute of Advanced Computer Science // Universiteit Leiden // All Rights Reserved // ******************************************************************* // Dou Shou Qi (interface) // ******************************************************************* // FILE INFORMATION: // File: jlkiss64.h // Author: Jonathan K. Vis // Revision: 1.01a // Date: 2013/04/18 // ******************************************************************* // DESCRIPTION: // 64-bits random number generator based on: ``The KISS generator'', // G. Marsaglia and A. Zaman, 1993. // ******************************************************************* #if !defined(__jlkiss64_h__) #define __jlkiss64_h__ #include "../core/types.h" class RNG { public: static RNG next; static void seed(uint64_t const n); uint64_t operator()(void); private: inline RNG(void); static uint64_t _x; uint64_t _y; uint32_t _z1; uint32_t _c1; uint32_t _z2; uint32_t _c2; }; // RNG uint64_t RNG::_x = 123456789123ull; inline void RNG::seed(uint64_t const n) { _x = RNG::next() ^ n; return; } // RNG::seed inline uint64_t RNG::operator()(void) { uint64_t t; _x = 1490024343005336237ull * _x + 123456789; _y ^= _y << 21; _y ^= _y >> 17; _y ^= _y << 30; t = 4294584393ull * _z1 + _c1; _c1 = t >> 32; _z1 = t; t = 4246477509ull * _z2 + _c2; _c2 = t >> 32; _z2 = t; return _x + _y + static_cast(_z1) + (static_cast(_z2) << 32); } // RNG::operator() inline RNG::RNG(void) { _y = 987654321987ull; _z1 = 43219876; _c1 = 6543217; _z2 = 21987643; _c2 = 1732654; } // RNG::RNG RNG RNG::next; #endif