Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
1 result

Target

Select target project
  • a24jacqb/pdptw-main
1 result
Select Git revision
  • main
1 result
Show changes
#include "utils.h"
#include "config.h"
#include <random>
namespace// anonymous namespace
{
std::mt19937_64 randomGenerator;// NOLINT(*-msc51-cpp) => deterministic random!
bool seedSet = false;
std::uniform_real_distribution<> distribution(0, 1);
}// namespace
double util::getRandom()
{
if (!seedSet) [[unlikely]]
{
randomGenerator.seed(RANDOM_SEED);
seedSet = true;
}
return distribution(randomGenerator);
}
unsigned int util::getRandomInt(unsigned int min, unsigned int max)
{
if (!seedSet) [[unlikely]]
{
randomGenerator.seed(RANDOM_SEED);
seedSet = true;
}
return std::uniform_int_distribution<>(min, max)(randomGenerator);
}
std::mt19937_64 &util::getRawRandom()
{
if (!seedSet) [[unlikely]]
{
randomGenerator.seed(RANDOM_SEED);
seedSet = true;
}
return randomGenerator;
}
#pragma once
#include <algorithm>
#include <functional>
#include <memory>
#include <random>
#include <stdexcept>
#include <string>
#include <vector>
namespace util
{
/**
* Get a random number
* @return a number between 0 (inclusive) and 1 (exclusive)
*/
double getRandom();
/**
* @return a random integer number between min (included) and max (included)
*/
unsigned int getRandomInt(unsigned int min, unsigned int max);
/**
* @return the random generator directly, it is a deterministic random
*/
std::mt19937_64 &getRawRandom();
}// namespace util