-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.h
More file actions
46 lines (38 loc) · 755 Bytes
/
random.h
File metadata and controls
46 lines (38 loc) · 755 Bytes
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
44
45
46
#ifndef RANDOM_H
#define RANDOM_H
#include <cstdlib>
#include <cassert>
class Random
{
public:
Random();
~Random();
static void between0and1( double *v, const int &num )
{
assert( v!= NULL);
assert( num > 1);
for(int i=0; i<num; i++)
{
v[i] = static_cast<double>( std::rand() ) / RAND_MAX;
}
}
static double betweenMinus2and2(void)
{
return 2.0*betweenMinus1and1();
}
static double betweenMinus1and1(void)
{
int a = std::rand() % 2;
if(a==0) return between0and1();
else if(a==1) return betweenMinus1and0();
}
static double between0and1(void)
{
return static_cast<double>( std::rand() )/RAND_MAX;
}
static double betweenMinus1and0(void)
{
return -static_cast<double>( std::rand() )/RAND_MAX;
}
};
#endif