From 42dcfe069fe24a5a63709b08e35ed6830ce327e1 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 9 Jul 2024 18:07:12 -0400 Subject: [PATCH] randomness renaming --- CMakeLists.txt | 2 +- include/blt/std/random.h | 46 ++++++++++++++++++++------------------ libraries/parallel-hashmap | 2 +- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32680f5..07046c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.18.0) +set(BLT_VERSION 0.18.1) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/std/random.h b/include/blt/std/random.h index eb83342..02a285b 100644 --- a/include/blt/std/random.h +++ b/include/blt/std/random.h @@ -14,7 +14,7 @@ namespace blt::random { // https://github.com/avaneev/komihash/tree/main - static inline blt::u32 PCG_Hash(blt::u32 input) + static inline blt::u32 pcg_hash32(blt::u32 input) { blt::u32 state = input * 747796405u + 2891336453u; blt::u32 word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u; @@ -32,28 +32,28 @@ namespace blt::random return h; } - static inline double pcg_double(blt::u32& seed) + static inline double pcg_double32(blt::u32& seed) { - seed = PCG_Hash(seed); + seed = pcg_hash32(seed); return static_cast(seed) / static_cast(std::numeric_limits::max()); } - static inline float pcg_float(blt::u32& seed) + static inline float pcg_float32(blt::u32& seed) { - return static_cast(pcg_double(seed)); + return static_cast(pcg_double32(seed)); } /** * @return random float without changing seed */ - static inline float pcg_float_c(blt::u32 seed) + static inline float pcg_float32c(blt::u32 seed) { - return pcg_float(seed); + return pcg_float32(seed); } - static inline double pcg_double_c(blt::u32 seed) + static inline double pcg_double32c(blt::u32 seed) { - return pcg_double(seed); + return pcg_double32(seed); } /** @@ -62,46 +62,48 @@ namespace blt::random * @param max exclusive max * @return random int between min (inclusive) and max (exclusive) */ - static inline int pcg_int(blt::u32& seed, int min = 0, int max = 2) + template + static inline T pcg_random32(blt::u32& seed, T min = 0, T max = 2) { - return static_cast((pcg_double(seed) * static_cast(max - min)) + static_cast(min)); + return static_cast((pcg_double32(seed) * static_cast(max - min)) + static_cast(min)); } - static inline int pcg_int_c(blt::u32 seed, int min = 0, int max = 2) + template + static inline T pcg_random32c(blt::u32 seed, T min = 0, T max = 2) { return pcg_int(seed, min, max); } - static inline double murmur_double(blt::u64& seed) + static inline double murmur_double64(blt::u64& seed) { seed = murmur64(seed); return static_cast(seed) / static_cast(std::numeric_limits::max()); } - static inline float murmur_float(blt::u64& seed) + static inline float murmur_float64(blt::u64& seed) { - return static_cast(murmur_double(seed)); + return static_cast(murmur_double64(seed)); } - static inline float murmur_float_c(blt::u64 seed) + static inline float murmur_float64c(blt::u64 seed) { - return murmur_float(seed); + return murmur_float64(seed); } - static inline double murmur_double_c(blt::u64 seed) + static inline double murmur_double64c(blt::u64 seed) { - return murmur_double(seed); + return murmur_double64(seed); } template - static inline T murmur_integral_64(blt::u64& seed, T min = 0, T max = 2) + static inline T murmur_random64(blt::u64& seed, T min = 0, T max = 2) { - return static_cast((murmur_double(seed) * static_cast(max - min)) + static_cast(min)); + return static_cast((murmur_double64(seed) * static_cast(max - min)) + static_cast(min)); } template - static inline T murmur_integral_64c(blt::u64 seed, T min = 0, T max = 2) + static inline T murmur_random64c(blt::u64 seed, T min = 0, T max = 2) { return murmur_integral_64(seed, min, max); } diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index e5b892b..d88c5e1 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit e5b892baed478513adcb6425773cae1eda033057 +Subproject commit d88c5e15079047777b418132ece5879e7c9aaa2b