Per-thread RNGs and RNG bugfix
This commit is contained in:
parent
a45ae025d6
commit
52806e4457
6 changed files with 70 additions and 39 deletions
|
|
@ -8,11 +8,8 @@
|
|||
#include "timer.hpp"
|
||||
#include "random.h"
|
||||
|
||||
#define FAST_RANDOM 1
|
||||
#ifdef FAST_RANDOM
|
||||
pcg32_random_t pcg = { 0x853c49e6748fea9bULL, 0xda3e39cb94b95bdbULL };
|
||||
#define rand() pcg32_random_r(&pcg)
|
||||
#endif
|
||||
pcg32_random_t *pcg_table;
|
||||
pcg32_random_t default_pcg = { 0x853c49e6748fea9bULL, 0xda3e39cb94b95bdbULL };
|
||||
|
||||
/* Utility functions */
|
||||
inline float degrees_to_radians(float d)
|
||||
|
|
@ -21,15 +18,21 @@ inline float degrees_to_radians(float d)
|
|||
}
|
||||
|
||||
/* Returns a float in the range [0,1) */
|
||||
inline float random_float()
|
||||
inline float random_float_()
|
||||
{
|
||||
return rand() * (1.0 / RAND_MAX);
|
||||
}
|
||||
|
||||
/* Returns a float in the range [min,max) */
|
||||
inline float random_float(float min, float max)
|
||||
/* Returns a float in the range [0,1) */
|
||||
inline float random_float(int32_t thread_id = 0)
|
||||
{
|
||||
return min + (max-min) * random_float();
|
||||
return pcg32_random_r(&pcg_table[thread_id]) * (1.0 / UINT32_MAX);
|
||||
}
|
||||
|
||||
/* Returns a float in the range [min,max) */
|
||||
inline float random_float(float min, float max, int32_t thread_id = 0)
|
||||
{
|
||||
return min + (max-min) * random_float(thread_id);
|
||||
}
|
||||
|
||||
/* Clamps a value between [min,max] */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue