Random.cpp 480 B

1234567891011121314151617181920212223242526
  1. #include <chrono>
  2. #include "common/utils/Random.h"
  3. Random::Random() : seed(std::chrono::steady_clock::now().time_since_epoch().count()) {
  4. }
  5. Random::Random(u64 seed) : seed(seed) {
  6. }
  7. u32 Random::next() {
  8. return nextSeed() >> 24;
  9. }
  10. u32 Random::next(uint bound) {
  11. return next() % bound;
  12. }
  13. float Random::nextFloat() {
  14. return next() * (1.0f / (0xFFFFFF + 1.0f));
  15. }
  16. u64 Random::nextSeed() {
  17. seed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFF;
  18. return seed;
  19. }