Changeset View
Changeset View
Standalone View
Standalone View
src/test/lcg.h
- This file was added.
// Copyright (c) 2019 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | |||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
#ifndef BITCOIN_TEST_LCH_H | |||||
#define BITCOIN_TEST_LCH_H | |||||
#include <cstdint> | |||||
// Simple 32-bit linear congruential generator with 64-bit internal state, | |||||
// 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). | |||||
// Knuth, Donald (1997). Seminumerical Algorithms Vol2. Sec 3.3.4. 3rd Ed. | |||||
// | |||||
// Low bits have short period, hence we use high bits which should have | |||||
// the same period as the entire generator (2^64). | |||||
class LCG64 { | |||||
uint64_t state; | |||||
public: | |||||
LCG64(uint64_t initialstate = 0) : state(initialstate) {} | |||||
uint32_t next() { | |||||
uint64_t oldstate = state; | |||||
deadalnix: You can compute the return value directly here. | |||||
state = oldstate * 6364136223846793005 + 1442695040888963407; | |||||
deadalnixUnsubmitted Not Done Inline Actionsand just use state here :) deadalnix: and just use state here :) | |||||
return oldstate >> 32; | |||||
} | |||||
}; | |||||
#endif |
You can compute the return value directly here.