123456789101112131415161718192021222324252627282930 |
- #include <chrono>
- #include "common/utils/Random.h"
- Random::Random() : seed(std::chrono::steady_clock::now().time_since_epoch().count()) {
- }
- Random::Random(u64 seed) : seed(seed) {
- }
- u32 Random::next() {
- return nextSeed() >> 24;
- }
- u32 Random::next(uint bound) {
- return next() % bound;
- }
- float Random::nextFloat() {
- return next() * (1.0f / (0xFFFFFF + 1.0f));
- }
- float Random::nextFloat(float scale) {
- return (nextFloat() - 0.5f) * 2.0f * scale;
- }
- u64 Random::nextSeed() {
- seed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFF;
- return seed;
- }
|