From e722799876b7644b9b84d00fdc7a9cdb7ea08c28 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Thu, 20 Apr 2023 19:35:06 -0300 Subject: [PATCH] Neatens in src/bitrand (#12) --- src/bitrand/CMakeLists.txt | 1 - src/bitrand/psdes.cpp | 10 +++++----- src/bitrand/psdes.h | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/bitrand/CMakeLists.txt b/src/bitrand/CMakeLists.txt index ffc3a10..06158fc 100644 --- a/src/bitrand/CMakeLists.txt +++ b/src/bitrand/CMakeLists.txt @@ -5,7 +5,6 @@ project(bitrand) add_library(${PROJECT_NAME} psdes.cpp ) -#add_library(sub::lib1 ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include diff --git a/src/bitrand/psdes.cpp b/src/bitrand/psdes.cpp index c36ba4e..f3a117a 100644 --- a/src/bitrand/psdes.cpp +++ b/src/bitrand/psdes.cpp @@ -17,21 +17,21 @@ static uint32_t non_reentrant_seeded = 0; // ---------------------------------------------------------------- uint32_t iran32(void) { if (!non_reentrant_seeded) - sran32_tod(); + sran32_timeofday(); return iran32_r(non_reentrant_state0, non_reentrant_state1); } // ---------------------------------------------------------------- void iran64(uint32_t &out0, uint32_t &out1) { if (!non_reentrant_seeded) - sran32_tod(); + sran32_timeofday(); return iran64_r(out0, out1, non_reentrant_state0, non_reentrant_state1); } // ---------------------------------------------------------------- float fran32(void) { if (!non_reentrant_seeded) - sran32_tod(); + sran32_timeofday(); return fran32_r(non_reentrant_state0, non_reentrant_state1); } @@ -50,7 +50,7 @@ void sran32b(uint32_t s0, uint32_t s1) { } // ---------------------------------------------------------------- -void sran32_tod(void) { +void sran32_timeofday(void) { struct timeval tod; (void)gettimeofday(&tod, 0); non_reentrant_state0 = getpid() ^ tod.tv_usec; @@ -94,7 +94,7 @@ float fran32_r(uint32_t &state0, uint32_t &state1) { } // ---------------------------------------------------------------- -void sran32_tod_r(uint32_t &state0, uint32_t &state1) { +void sran32_timeofday_r(uint32_t &state0, uint32_t &state1) { struct timeval tod; (void)gettimeofday(&tod, 0); state0 = getpid() ^ tod.tv_usec; diff --git a/src/bitrand/psdes.h b/src/bitrand/psdes.h index e8dd6f8..712fdcd 100644 --- a/src/bitrand/psdes.h +++ b/src/bitrand/psdes.h @@ -53,7 +53,7 @@ // // * For the reentrant versions, you must seed the generator (i.e. assign // values to the two 32-bit state values) yourself. For convenience, -// a function (sran32_tod_r) is supplied, which you can use to obtain a +// a function (sran32_timeofday_r) is supplied, which you can use to obtain a // seed value which will probably be different on each call. // // * For the non-reentrant version, you may seed the generator if you wish, @@ -94,7 +94,7 @@ // * Reentrant version with time-of-day seeds: // // uint32_t state0, state1, rand; -// sran32_tod_r(1, &state0, &state1); +// sran32_timeofday_r(1, &state0, &state1); // rand = iran32(&state0, &state1); // rand = iran32(&state0, &state1); // rand = iran32(&state0, &state1); @@ -132,7 +132,7 @@ // ---------------------------------------------------------------- // These versions are non-reentrant. // Usage: Nominally, just call iran32() or fran32(). They remember whether -// or not a seed has been supplied, and call sran32_tod() if not. Use sran32() +// or not a seed has been supplied, and call sran32_timeofday() if not. Use sran32() // only if you want to force the same generator output each time. // Uniformly distributed pseudorandom 32-bit integer. @@ -153,7 +153,7 @@ void sran32b(uint32_t s0, uint32_t s1); // Sets all 64 bits of generator state to the values dependent on the // Unix PID, time of day in seconds, and time of day in microseconds. -void sran32_tod(void); +void sran32_timeofday(void); // ---------------------------------------------------------------- // These versions are reentrant. @@ -171,7 +171,7 @@ float fran32_r(uint32_t &state0, uint32_t &state1); // assign to them whatever values you wish. // This puts time-of-day information into your state variables. -void sran32_tod_r(uint32_t &state0, uint32_t &state1void); +void sran32_timeofday_r(uint32_t &state0, uint32_t &state1void); // ---------------------------------------------------------------- // This is the 64-bit pseudo-DES in-place hash.