stupid cross platform randomness issue, plus other fixes
This commit is contained in:
39
src/engine/random.c
Normal file
39
src/engine/random.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include "random.h"
|
||||
|
||||
void
|
||||
random_seed_set(u64 seed)
|
||||
{
|
||||
jsw_seed(seed);
|
||||
}
|
||||
|
||||
void
|
||||
random_seed_time_set(void)
|
||||
{
|
||||
jsw_time_seed();
|
||||
}
|
||||
|
||||
f32
|
||||
random_f32(void)
|
||||
{
|
||||
return (f32)jsw_rand() / (f32)UINT_MAX;
|
||||
}
|
||||
|
||||
f32
|
||||
random_f32_in_range(f32 min, f32 max)
|
||||
{
|
||||
return (f32)((random_f32() * (max - min + 1)) + min);
|
||||
}
|
||||
|
||||
|
||||
s32
|
||||
random_s32_in_range(s32 min, s32 max)
|
||||
{
|
||||
return (s32)((random_f32() * (max - min + 1)) + min);
|
||||
}
|
||||
|
||||
bool
|
||||
random_bool(void)
|
||||
{
|
||||
return random_s32_in_range(0, 2);
|
||||
}
|
||||
|
12
src/engine/random.h
Normal file
12
src/engine/random.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
#include <jsw_rand.h>
|
||||
|
||||
void random_seed_set(u64 seed);
|
||||
void random_seed_time_set(void);
|
||||
f32 random_f32(void);
|
||||
f32 random_f32_in_range(f32 min, f32 max);
|
||||
s32 random_s32_in_range(s32 min, s32 max);
|
||||
bool random_bool(void);
|
Reference in New Issue
Block a user