Very bad randomness

This commit is contained in:
Edgaru089 2024-03-26 13:26:22 +08:00
parent 19895363a3
commit dcca8a348a
3 changed files with 26 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "types.h"
#include "util/rand.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@ -41,6 +42,10 @@ Vec2 vec2_Scale(Vec2 v, double scale) {
}
Vec2 vec2_Random(double minX, double maxX, double minY, double maxY) {
Vec2 result = {
.x = minX + (maxX - minX) * rand_Double01(),
.y = minY + (maxY - minY) * rand_Double01()};
return result;
}

9
util/rand.c Normal file
View File

@ -0,0 +1,9 @@
#include "rand.h"
#include <stdlib.h>
double rand_Double01() {
// Very bad implementation.
return ((double)rand()) / (double)RAND_MAX;
}

12
util/rand.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
// returns a double in the [0,1) range.
double rand_Double01();
#ifdef __cplusplus
}
#endif