]>
git.bts.cx Git - benzene.git/blob - src/bz/math/random.c
1 #include <bz/math/random.h>
3 #include <bz/math/math.h>
7 float bzRandomFloat(float max
) {
8 uint32_t v
= pcg32_random() % 1000;
9 float value
= (float)v
/ 1000.0f
;
11 //return ((float)pcg32_random() / (float)UINTMAX_MAX);// * max;
14 float bzRandomFloatRange(float v1
, float v2
) {
18 float min
= bzMin(v1
, v2
);
19 float max
= bzMax(v1
, v2
);
20 float v
= bzRandomFloat(bzAbs(max
- min
)) * bzSgn(max
- min
);
25 uint32_t bzRandomInteger(uint32_t max
) {
26 return pcg32_boundedrand(max
);
29 int32_t bzRandomIntegerRange(int32_t v1
, int32_t v2
) {
33 int32_t min
= bzMin(v1
, v2
);
34 int32_t max
= bzMax(v1
, v2
);
35 int32_t v
= bzRandomInteger(bzAbs(max
- min
)) * bzSgn(max
- min
);
40 void *bzRandomArrayValue(size_t count
, size_t arrayTypeSize
, void *array
) {
41 uint32_t idx
= bzRandomInteger(count
);
42 return array
+ idx
* arrayTypeSize
;