aboutsummaryrefslogtreecommitdiff
path: root/source/splitmix64.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/splitmix64.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/splitmix64.h')
-rw-r--r--source/splitmix64.h44
1 files changed, 44 insertions, 0 deletions
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 <stdint.h>
+#include <stdbool.h>
+
+/* 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 */