aboutsummaryrefslogtreecommitdiff
path: root/source/wy_random.h
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot]2026-02-20 07:04:47 +0000
committercopilot-swe-agent[bot]2026-02-20 07:04:47 +0000
commit08cb1349ca394634c4e1df6cec423428e6b29ad6 (patch)
treebc9185730a2fd385d96c54ec6ca05bb51d8dc88c /source/wy_random.h
parent5999341c31b7ff44eb48bd38f9c12750c9ed8720 (diff)
downloadlibrandom-08cb1349ca394634c4e1df6cec423428e6b29ad6.tar.xz
librandom-08cb1349ca394634c4e1df6cec423428e6b29ad6.tar.zst
Add XorShift, SplitMix64, WyRandom, PCG, and XoroShiro generators
Co-authored-by: 8e8m <248551607+8e8m@users.noreply.github.com>
Diffstat (limited to 'source/wy_random.h')
-rw-r--r--source/wy_random.h44
1 files changed, 44 insertions, 0 deletions
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 <stdint.h>
+#include <stdbool.h>
+
+/* 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 */