#include "aliases.h" #include "ppm.h" #include #include #include typedef struct { u64 x; u64 y; u64 z; u64 w; } XORShift256; void test_xorshift_256(Pixel *data, u64 w, u64 h); u64 xorshift_256_generate(XORShift256 *state); int main(int argc, char *argv[]) { struct timespec ts = {0}; clock_gettime(CLOCK_MONOTONIC_RAW, &ts); srand48(ts.tv_nsec); u64 w = 1024; u64 h = 1024; u64 length = w * h; Pixel data[length]; test_xorshift_256(data, w, h); write_p6_ppm("./outputs/xorshift_256.ppm", w, h, data); return EXIT_SUCCESS; } void test_xorshift_256(Pixel *data, u64 w, u64 h) { XORShift256 state = { .x = lrand48(), .y = lrand48(), .z = lrand48(), .w = lrand48(), }; for (u64 y = 0; y < h; ++y) { for (u64 x = 0; x < w; ++x) { u64 i = y * w + x; u8 pixel = xorshift_256_generate(&state) % UINT8_MAX; data[i] = (Pixel){ .r = pixel, .g = pixel, .b = pixel, }; } } } u64 xorshift_256_generate(XORShift256 *state) { u64 t = state->x ^ (state->x << 11); state->x = state->y; state->y = state->z; state->z = state->w; state->w = (state->w ^ (state->w >> 19)) ^ (t ^ (t >> 8)); return state->w; }