blob: cf2a9702dd2c6e8160d3770ea1195422e88c9ac7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//
//
// C++ Interface for module: Random
//
// Description:
//
//
// Author: exa
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef Random_Interface
#define Random_Interface
#include <cstdlib>
#include <time.h>
// wrapper for random functions
class Random {
public:
int operator() (int N) {
return random_int (N);
}
static void init() {
seed += time(0);
srandom(seed);
}
static double random_double (double upper_bound) {
return double(random()) * upper_bound / RAND_MAX;
}
static int random_int (int upper_bound) {
return random() % upper_bound;
}
private:
static int seed;
};
#endif
|