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/wy_random.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 source/wy_random.h (limited to 'source/wy_random.h') diff --git a/source/wy_random.h b/source/wy_random.h new file mode 100644 index 0000000..80afb43 --- /dev/null +++ b/source/wy_random.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 WY_RANDOM_H +#define WY_RANDOM_H + +#include +#include + +/* WyRandom: A wyhash-inspired PRNG variant leveraging multiply-mix operations. + * + * Designed around 64-bit multiply-and-mix steps, this generator is fast and + * suitable for general-purpose randomness and hashing-like use cases. + * + * Pros: + * - Fast and simple; good distribution for typical gameplay uses + * - Deterministic across platforms + * + * Cons: + * - Not cryptographically secure + */ + +typedef struct { + uint64_t state; +} wy_random_t; + +/* Initialize the generator with a seed */ +void wy_init(wy_random_t *rng, uint64_t seed); + +/* Generate next random 32-bit unsigned integer */ +uint32_t wy_next_uint(wy_random_t *rng); + +/* Generate next random 64-bit unsigned integer */ +uint64_t wy_next_ulong(wy_random_t *rng); + +/* Generate next random float in [0, 1) */ +float wy_next_float(wy_random_t *rng); + +/* Generate next random double in [0, 1) */ +double wy_next_double(wy_random_t *rng); + +#endif /* WY_RANDOM_H */ -- cgit v1.2.3