This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
The-Powder-Toy/src/common/tpt-rand.h
Tamás Bálint Misius eee42b2ea3
Fix RNG usage
Mostly boils down to having graphics functions use Renderer's RNG, update and similar functions Simulation's.
2023-04-15 18:22:03 +02:00

26 lines
613 B
C++

#pragma once
#include "ExplicitSingleton.h"
#include <stdint.h>
#include <array>
class RNG
{
private:
std::array<uint64_t, 2> s;
uint64_t next();
public:
unsigned int operator()();
unsigned int gen();
int between(int lower, int upper);
bool chance(int nominator, unsigned int denominator);
float uniform01();
RNG();
void seed(unsigned int sd);
};
// Please only use this on the main thread and never for simulation stuff.
// For simulation stuff, use Simulation::rng. For renderer stuff, use Renderer::rng.
// For anything else, prefer a dedicated RNG instance over this one.
extern RNG interfaceRng;