From b26cd4ffd1e4b6ee6c3567ffa0c84d6cd7960244 Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm <philipp@uvos.xyz> Date: Tue, 30 May 2023 14:19:08 +0200 Subject: [PATCH] add missing files --- randomgen.cpp | 25 +++++++++++++++++++++++++ randomgen.h | 12 ++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 randomgen.cpp create mode 100644 randomgen.h diff --git a/randomgen.cpp b/randomgen.cpp new file mode 100644 index 0000000..4219cce --- /dev/null +++ b/randomgen.cpp @@ -0,0 +1,25 @@ +#include "randomgen.h" +#include <assert.h> +#include <cstddef> +#include <cstdint> +#include <random> + +static std::default_random_engine randomEngine; +static std::uniform_real_distribution<double> dist(0, 1); +static std::uniform_int_distribution<size_t> distSt(0, SIZE_MAX); + +double rd::rand(double max) +{ + return dist(randomEngine)*max; +} + +size_t rd::uid() +{ + return distSt(randomEngine); +} + +void rd::init() +{ + std::random_device randomDevice; + randomEngine.seed(randomDevice()); +} diff --git a/randomgen.h b/randomgen.h new file mode 100644 index 0000000..014bf98 --- /dev/null +++ b/randomgen.h @@ -0,0 +1,12 @@ +#pragma once + +#include <cstddef> + +namespace rd +{ + +double rand(double max = 1); +void init(); +size_t uid(); + +} -- GitLab