Standardize naming conventions #12
@@ -17,7 +17,7 @@ wp_intern u64 split_mix_64(SplitMix64State *state);
|
|||||||
wp_intern void seed_os_generator(void);
|
wp_intern void seed_os_generator(void);
|
||||||
wp_intern u64 generate_random_number(void);
|
wp_intern u64 generate_random_number(void);
|
||||||
|
|
||||||
XOR256State wapp_prng_xorshift_init_state(void) {
|
WpXor256State wpPrngXorshiftInit(void) {
|
||||||
wp_persist b8 seeded = false;
|
wp_persist b8 seeded = false;
|
||||||
if (!seeded) {
|
if (!seeded) {
|
||||||
seeded = true;
|
seeded = true;
|
||||||
@@ -26,7 +26,7 @@ XOR256State wapp_prng_xorshift_init_state(void) {
|
|||||||
|
|
||||||
SplitMix64State sm64 = {.seed = generate_random_number()};
|
SplitMix64State sm64 = {.seed = generate_random_number()};
|
||||||
|
|
||||||
return (XOR256State){
|
return (WpXor256State){
|
||||||
.x = split_mix_64(&sm64),
|
.x = split_mix_64(&sm64),
|
||||||
.y = split_mix_64(&sm64),
|
.y = split_mix_64(&sm64),
|
||||||
.z = split_mix_64(&sm64),
|
.z = split_mix_64(&sm64),
|
||||||
@@ -34,7 +34,7 @@ XOR256State wapp_prng_xorshift_init_state(void) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 wapp_prng_xorshift_256(XOR256State *state) {
|
u64 wpPrngXorshift256(WpXor256State *state) {
|
||||||
u64 t = state->x ^ (state->x << 11);
|
u64 t = state->x ^ (state->x << 11);
|
||||||
|
|
||||||
state->x = state->y;
|
state->x = state->y;
|
||||||
@@ -45,7 +45,7 @@ u64 wapp_prng_xorshift_256(XOR256State *state) {
|
|||||||
return state->w;
|
return state->w;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 wapp_prng_xorshift_256ss(XOR256State *state) {
|
u64 wpPrngXorshift256ss(WpXor256State *state) {
|
||||||
const u64 result = rol64(state->z * 5, 7) * 9;
|
const u64 result = rol64(state->z * 5, 7) * 9;
|
||||||
const u64 t = state->z << 17;
|
const u64 t = state->z << 17;
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ u64 wapp_prng_xorshift_256ss(XOR256State *state) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 wapp_prng_xorshift_256p(XOR256State *state) {
|
u64 wpPrngXorshift256p(WpXor256State *state) {
|
||||||
const u64 result = state->w + state->x;
|
const u64 result = state->w + state->x;
|
||||||
const u64 t = state->z << 17;
|
const u64 t = state->z << 17;
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,18 @@
|
|||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
#endif // !WP_PLATFORM_CPP
|
#endif // !WP_PLATFORM_CPP
|
||||||
|
|
||||||
typedef struct XOR256State XOR256State;
|
typedef struct WpXor256State WpXor256State;
|
||||||
struct XOR256State {
|
struct WpXor256State {
|
||||||
u64 x;
|
u64 x;
|
||||||
u64 y;
|
u64 y;
|
||||||
u64 z;
|
u64 z;
|
||||||
u64 w;
|
u64 w;
|
||||||
};
|
};
|
||||||
|
|
||||||
XOR256State wapp_prng_xorshift_init_state(void);
|
WpXor256State wpPrngXorshiftInit(void);
|
||||||
u64 wapp_prng_xorshift_256(XOR256State *state);
|
u64 wpPrngXorshift256(WpXor256State *state);
|
||||||
u64 wapp_prng_xorshift_256ss(XOR256State *state);
|
u64 wpPrngXorshift256ss(WpXor256State *state);
|
||||||
u64 wapp_prng_xorshift_256p(XOR256State *state);
|
u64 wpPrngXorshift256p(WpXor256State *state);
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
|||||||
+4
-4
@@ -28,17 +28,17 @@ WpUuid *wpUuidInitUuid4(WpUuid *uuid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wp_intern UUID4 generate_uuid4(void) {
|
wp_intern UUID4 generate_uuid4(void) {
|
||||||
wp_persist XOR256State state = {0};
|
wp_persist WpXor256State state = {0};
|
||||||
wp_persist b8 initialised = false;
|
wp_persist b8 initialised = false;
|
||||||
|
|
||||||
if (!initialised) {
|
if (!initialised) {
|
||||||
initialised = true;
|
initialised = true;
|
||||||
state = wapp_prng_xorshift_init_state();
|
state = wpPrngXorshiftInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID4 uuid = (UUID4){
|
UUID4 uuid = (UUID4){
|
||||||
.high = wapp_prng_xorshift_256(&state),
|
.high = wpPrngXorshift256(&state),
|
||||||
.low = wapp_prng_xorshift_256(&state),
|
.low = wpPrngXorshift256(&state),
|
||||||
};
|
};
|
||||||
|
|
||||||
uuid.high = (uuid.high & 0xffffffffffff0fff) | 0x0000000000004000;
|
uuid.high = (uuid.high & 0xffffffffffff0fff) | 0x0000000000004000;
|
||||||
|
|||||||
Reference in New Issue
Block a user