mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
move rand functions from util to new random.h/.cpp
This commit is contained in:
51
src/util.h
51
src/util.h
@@ -90,8 +90,6 @@ inline void MilliSleep(int64_t n)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern std::map<std::string, std::string> mapArgs;
|
||||
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
|
||||
extern bool fDebug;
|
||||
@@ -103,9 +101,6 @@ extern bool fLogTimestamps;
|
||||
extern bool fLogIPs;
|
||||
extern volatile bool fReopenDebugLog;
|
||||
|
||||
bool GetRandBytes(unsigned char *buf, int num);
|
||||
void RandAddSeed();
|
||||
void RandAddSeedPerfmon();
|
||||
void SetupEnvironment();
|
||||
|
||||
/* Return true if log accepts specified category */
|
||||
@@ -188,23 +183,12 @@ boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
||||
#endif
|
||||
boost::filesystem::path GetTempPath();
|
||||
void ShrinkDebugFile();
|
||||
int GetRandInt(int nMax);
|
||||
uint64_t GetRand(uint64_t nMax);
|
||||
uint256 GetRandHash();
|
||||
int64_t GetTime();
|
||||
void SetMockTime(int64_t nMockTimeIn);
|
||||
std::string FormatFullVersion();
|
||||
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
|
||||
void runCommand(std::string strCommand);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline std::string i64tostr(int64_t n)
|
||||
{
|
||||
return strprintf("%d", n);
|
||||
@@ -290,19 +274,6 @@ inline std::string HexStr(const T& vch, bool fSpaces=false)
|
||||
*/
|
||||
std::string FormatParagraph(const std::string in, size_t width=79, size_t indent=0);
|
||||
|
||||
inline int64_t GetPerformanceCounter()
|
||||
{
|
||||
int64_t nCounter = 0;
|
||||
#ifdef WIN32
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&nCounter);
|
||||
#else
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
nCounter = (int64_t) t.tv_sec * 1000000 + t.tv_usec;
|
||||
#endif
|
||||
return nCounter;
|
||||
}
|
||||
|
||||
inline int64_t GetTimeMillis()
|
||||
{
|
||||
return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) -
|
||||
@@ -371,28 +342,6 @@ bool SoftSetArg(const std::string& strArg, const std::string& strValue);
|
||||
*/
|
||||
bool SoftSetBoolArg(const std::string& strArg, bool fValue);
|
||||
|
||||
/**
|
||||
* MWC RNG of George Marsaglia
|
||||
* This is intended to be fast. It has a period of 2^59.3, though the
|
||||
* least significant 16 bits only have a period of about 2^30.1.
|
||||
*
|
||||
* @return random value
|
||||
*/
|
||||
extern uint32_t insecure_rand_Rz;
|
||||
extern uint32_t insecure_rand_Rw;
|
||||
static inline uint32_t insecure_rand(void)
|
||||
{
|
||||
insecure_rand_Rz = 36969 * (insecure_rand_Rz & 65535) + (insecure_rand_Rz >> 16);
|
||||
insecure_rand_Rw = 18000 * (insecure_rand_Rw & 65535) + (insecure_rand_Rw >> 16);
|
||||
return (insecure_rand_Rw << 16) + insecure_rand_Rz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed insecure_rand using the random pool.
|
||||
* @param Deterministic Use a determinstic seed
|
||||
*/
|
||||
void seed_insecure_rand(bool fDeterministic=false);
|
||||
|
||||
/**
|
||||
* Timing-attack-resistant comparison.
|
||||
* Takes time proportional to length
|
||||
|
||||
Reference in New Issue
Block a user