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);