Changeset View
Changeset View
Standalone View
Standalone View
src/test/lcg.h
// Copyright (c) 2019 The Bitcoin developers | // Copyright (c) 2019 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_TEST_LCH_H | #ifndef BITCOIN_TEST_LCG_H | ||||
#define BITCOIN_TEST_LCH_H | #define BITCOIN_TEST_LCG_H | ||||
#include <cstdint> | #include <cstdint> | ||||
// Simple 32-bit linear congruential generator with 64-bit internal state, | // Simple 32-bit linear congruential generator with 64-bit internal state, | ||||
// often called as "MMIX by Donald Knuth". Knuth attributes the multiplier | // often called as "MMIX by Donald Knuth". Knuth attributes the multiplier | ||||
// to C. E. Haynes and the increment is not crucial (it only need be odd). | // to C. E. Haynes and the increment is not crucial (it only need be odd). | ||||
// Knuth, Donald (1997). Seminumerical Algorithms Vol2. Sec 3.3.4. 3rd Ed. | // Knuth, Donald (1997). Seminumerical Algorithms Vol2. Sec 3.3.4. 3rd Ed. | ||||
// | // | ||||
Show All 10 Lines | public: | ||||
// (thus starting with 0, by default) | // (thus starting with 0, by default) | ||||
uint32_t next() { | uint32_t next() { | ||||
uint32_t ret = state >> 32; | uint32_t ret = state >> 32; | ||||
state = state * 6364136223846793005 + 1442695040888963407; | state = state * 6364136223846793005 + 1442695040888963407; | ||||
return ret; | return ret; | ||||
} | } | ||||
}; | }; | ||||
#endif | #endif // BITCOIN_TEST_LCG_H |