Luzhiled's Library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub ei1333/library

:warning: other/random-number-generator.hpp

Code

#pragma once

#include <chrono>
#include <random>

struct RandomNumberGenerator {
  std::mt19937 mt;

  RandomNumberGenerator()
      : mt(std::chrono::steady_clock::now().time_since_epoch().count()) {}

  int operator()(int a, int b) {  // [a, b)
    std::uniform_int_distribution<int> dist(a, b - 1);
    return dist(mt);
  }

  int operator()(int b) {  // [0, b)
    return (*this)(0, b);
  }
};
#line 2 "other/random-number-generator.hpp"

#include <chrono>
#include <random>

struct RandomNumberGenerator {
  std::mt19937 mt;

  RandomNumberGenerator()
      : mt(std::chrono::steady_clock::now().time_since_epoch().count()) {}

  int operator()(int a, int b) {  // [a, b)
    std::uniform_int_distribution<int> dist(a, b - 1);
    return dist(mt);
  }

  int operator()(int b) {  // [0, b)
    return (*this)(0, b);
  }
};
Back to top page