44 lines
999 B
C
44 lines
999 B
C
#include "intern/wapp/src/common/wapp_common.h"
|
|
#include "intern/wapp/src/prng/wapp_prng.h"
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
|
|
typedef struct uuid4 UUID4;
|
|
struct uuid4 {
|
|
u64 high;
|
|
u64 low;
|
|
};
|
|
|
|
UUID4 gen_uuid4(XOR256State *state);
|
|
void print_uuid4(UUID4 uuid);
|
|
|
|
int main(void) {
|
|
XOR256State state = wapp_init_xor_256_state();
|
|
|
|
for (int i = 0; i < 100000; ++i) {
|
|
UUID4 uuid = gen_uuid4(&state);
|
|
print_uuid4(uuid);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
UUID4 gen_uuid4(XOR256State *state) {
|
|
persistent u64 and_mask = 0xffffffffffff0fff;
|
|
persistent u64 or_mask = 0x0000000000004000;
|
|
UUID4 uuid = { .high = wapp_xorshift_256_generate(state), .low = wapp_xorshift_256_generate(state) };
|
|
uuid.high &= and_mask;
|
|
uuid.high |= or_mask;
|
|
return uuid;
|
|
}
|
|
|
|
void print_uuid4(UUID4 uuid) {
|
|
u64 a = uuid.high >> 32;
|
|
u64 b = (uuid.high << 32) >> 48;
|
|
u64 c = (uuid.high << 48) >> 48;
|
|
u64 d = uuid.low >> 48;
|
|
u64 e = (uuid.low << 16) >> 16;
|
|
|
|
printf("%.8llx-%.4llx-%.4llx-%.4llx-%.12llx\n", a, b, c, d, e);
|
|
}
|