-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.cpp
More file actions
41 lines (32 loc) · 704 Bytes
/
Random.cpp
File metadata and controls
41 lines (32 loc) · 704 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
#include "Random.h"
#include <cstdlib>
#include <ctime>
int cheat()
{
srand( time(0) );
return 0;
}
int cheater = cheat();
// Postcondition: min <= random(min,max) < max
int random( int min, int max )
{
if( max-min == 0 )
return min;
return rand()%(max-min) + min;
}
float random( float min, float max )
{
const float PRECISION = 1000;
int val = random( int(min*PRECISION), int(max*PRECISION) );
return val / PRECISION;
}
double random( double min, double max )
{
const double PRECISION = 10000;
int val = random( int(min*PRECISION), int(max*PRECISION) );
return val / PRECISION;
}
double random_angle()
{
return random(0.0,3.14159265) * 2;
}