aboutsummaryrefslogtreecommitdiff
path: root/source/splitmix64.h
blob: 27d7edaaeb12d3bebfcbaa3d889a2eb7d8bba761 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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 */