From 88895a537a3b9ba319c70da5cbd826b9d246aa68 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Fri, 19 Feb 2016 00:31:27 +0300 Subject: [PATCH] add double and size_t to random --- random.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/random.h b/random.h index 0d4911a..9999708 100644 --- a/random.h +++ b/random.h @@ -35,18 +35,31 @@ class Random { return ((randomEngine() << 32) ^ randomEngine()) % n; } - int next(int l, int r) { - return l + next(r-l+1); + size_t next(size_t n) { + // TODO(ifsmirnov): make random more uniform + return ((randomEngine() << 32) ^ randomEngine()) % n; } - int next(size_t l, size_t r) { - return l + next(static_cast(r-l+1)); + double next(double n) { + return (double)randomEngine() / randomEngine.max() * n; + } + + int next(int l, int r) { + return l + next(r-l+1); } long long next(long long l, long long r) { return r + next(r-l+1); } + size_t next(size_t l, size_t r) { + return l + next(r-l+1); + } + + double next(double l, double r) { + return l + next(r-l); + } + template std::vector combination(T n, size_t k) { ensure(k <= n);