From 08cb1349ca394634c4e1df6cec423428e6b29ad6 Mon Sep 17 00:00:00 2001 From: copilot-swe-agent[bot] Date: Fri, 20 Feb 2026 07:04:47 +0000 Subject: Add XorShift, SplitMix64, WyRandom, PCG, and XoroShiro generators Co-authored-by: 8e8m <248551607+8e8m@users.noreply.github.com> --- source/splitmix64.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 source/splitmix64.h (limited to 'source/splitmix64.h') diff --git a/source/splitmix64.h b/source/splitmix64.h new file mode 100644 index 0000000..27d7eda --- /dev/null +++ b/source/splitmix64.h @@ -0,0 +1,44 @@ +/* MIT License - Copyright (c) 2025 wallstop + * Original C# implementation from: https://github.com/wallstop/unity-helpers + * Converted to C for librandom project + */ + +#ifndef SPLITMIX64_H +#define SPLITMIX64_H + +#include +#include + +/* SplitMix64: A fast 64-bit generator often used as a high-quality seeding/mixing PRNG. + * + * SplitMix64 is widely used to quickly generate well-distributed 64-bit values + * and as a seed source for other generators. + * + * Pros: + * - Very fast; great as a hash/mixer and for seed generation + * - Deterministic, portable, and simple + * + * Cons: + * - Not cryptographically secure + */ + +typedef struct { + uint64_t state; +} splitmix64_t; + +/* Initialize the generator with a seed */ +void splitmix64_init(splitmix64_t *rng, uint64_t seed); + +/* Generate next random 32-bit unsigned integer */ +uint32_t splitmix64_next_uint(splitmix64_t *rng); + +/* Generate next random 64-bit unsigned integer */ +uint64_t splitmix64_next_ulong(splitmix64_t *rng); + +/* Generate next random float in [0, 1) */ +float splitmix64_next_float(splitmix64_t *rng); + +/* Generate next random double in [0, 1) */ +double splitmix64_next_double(splitmix64_t *rng); + +#endif /* SPLITMIX64_H */ -- cgit v1.2.3