From 63b71bb16e37ac76ad06bf09e022a7454cc2c3b3 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 10 Mar 2019 22:17:02 -0400 Subject: [PATCH] checked in qcheck with sample code for new prng --- inc/qcheck.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/inc/qcheck.h b/inc/qcheck.h index 16fcfb7..6146d29 100644 --- a/inc/qcheck.h +++ b/inc/qcheck.h @@ -37,6 +37,12 @@ typedef struct { QCValue** vals; } QCResult; +typedef struct { + uint64_t state; + uint64_t mult; + uint64_t incr; +} QCRand_t; + typedef int (*QCProp)(int nvals, QCValue** vals); typedef QCValue* (*QCGenFn)(void); @@ -103,6 +109,29 @@ QCValue* GenAsciiString(void); static int Seed = 0, NTrials = 1000; + +int myrand(rand_t* rand) { + uint64_t x = rand->state; + unsigned count = (unsigned)(x >> 59); + rand->state = x * rand->mult + rand->incr; + x ^= x >> 18; + x = (uint32_t)(x >> 27); + return (x >> count | x << (-count & 31)); +} + +void mysrand(rand_t* rand, uint64_t seed) { + rand->state = 0x4d595df4d0f33173; + rand->mult = 6364136223846793005u; + rand->incr = 1442695040888963407u; + if (seed) { + rand->state = seed + rand->incr; + (void)myrand(rand); + } +} + + + + void qcinit(int seed) { Seed = (seed ? seed : time(NULL)); srand(Seed); -- 2.52.0