Skip to content

Commit

Permalink
add double and size_t to random
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsmirnov committed Feb 18, 2016
1 parent 7e73a72 commit 88895a5
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions random.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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<typename T>
std::vector<T> combination(T n, size_t k) {
ensure(k <= n);
Expand Down

0 comments on commit 88895a5

Please sign in to comment.