Implement RNG module

This commit is contained in:
2025-09-23 15:36:08 +01:00
parent 036b8fd4d3
commit 5d48f61406
4 changed files with 40 additions and 0 deletions

23
src/rng.c Normal file
View File

@@ -0,0 +1,23 @@
#include "rng.h"
#include <limits.h>
#include <stdlib.h>
#include <sys/time.h>
void rng_init()
{
struct timeval tv;
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
}
double rng_double()
{
return 2.0 * (double)rand() / (double)INT_MAX - 1.0;
}
vec3_t rng_vec3()
{
const vec3_t v = { rng_double(), rng_double(), rng_double() };
return vec3_unit(v);
}