Very bad randomness
This commit is contained in:
parent
19895363a3
commit
dcca8a348a
5
types.c
5
types.c
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "util/rand.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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 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
9
util/rand.c
Normal 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
12
util/rand.h
Normal 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
|
Loading…
Reference in New Issue
Block a user