mirror of
https://github.com/Relintai/pandemonium_engine_minimal.git
synced 2024-11-10 20:12:10 +01:00
33 lines
738 B
C++
33 lines
738 B
C++
|
|
/* random_pcg.cpp */
|
|
|
|
|
|
#include "random_pcg.h"
|
|
|
|
#include "core/os/os.h"
|
|
|
|
RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) :
|
|
pcg(),
|
|
current_inc(p_inc) {
|
|
seed(p_seed);
|
|
}
|
|
|
|
void RandomPCG::randomize() {
|
|
seed((OS::get_singleton()->get_unix_time() + OS::get_singleton()->get_ticks_usec()) * pcg.state + PCG_DEFAULT_INC_64);
|
|
}
|
|
|
|
double RandomPCG::random(double p_from, double p_to) {
|
|
return randd() * (p_to - p_from) + p_from;
|
|
}
|
|
|
|
float RandomPCG::random(float p_from, float p_to) {
|
|
return randf() * (p_to - p_from) + p_from;
|
|
}
|
|
|
|
int RandomPCG::random(int p_from, int p_to) {
|
|
if (p_from == p_to) {
|
|
return p_from;
|
|
}
|
|
return rand(abs(p_from - p_to) + 1) + MIN(p_from, p_to);
|
|
}
|