Skip to content

Commit

Permalink
Neatens in src/bitrand (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl authored Apr 20, 2023
1 parent d1faf68 commit e722799
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/bitrand/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/bitrand/psdes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/bitrand/psdes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit e722799

Please sign in to comment.