From 05ceb78f91aeece2b58cb32b46cd29ed92739ce7 Mon Sep 17 00:00:00 2001 From: CompiledCode Date: Thu, 24 Jun 2021 01:24:11 +0000 Subject: [PATCH] better number gen --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9088bb3..81f83cb 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,18 @@ This repo contains a list of utils that will probably need to be implimented for * llo::utils::generate_random, generate a random numerical value. ```cpp -template -auto generate_random() -> T +template, number_t>> +number_t generate_random_number(const number_t minimum, const number_t maximum) { - std::random_device rd; - std::mt19937 mt(rd()); - std::uniform_real_distribution dist(1.0, 10.0); - return dist(mt); + using uniform_distribution_t = std::conditional_t, std::uniform_int_distribution, std::uniform_real_distribution<>>; + + std::random_device random_device; + + auto mt = std::mt19937{ random_device() }; + + auto uniform_distribution = uniform_distribution_t{ minimum, maximum }; + + return uniform_distribution(mt); } ```