-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRNG.cpp
More file actions
40 lines (33 loc) · 705 Bytes
/
RNG.cpp
File metadata and controls
40 lines (33 loc) · 705 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
#include "RNG.hpp"
#include <cstdint>
#include <cstdlib>
#include <time.h>
#include <iostream>
RNG::RNG() {
this->seed = (uint16_t)clock();
srand (seed);
}
RNG::RNG(uint16_t seed) {
this->seed = seed;
srand (seed);
}
uint16_t RNG::getSeed() {
return seed;
}
uint16_t RNG::next(uint16_t max){
return uint16_t(rand() % max);
}
double RNG::randZeroToOne(){
return rand() / (RAND_MAX + 1.);
}
bool RNG::trueFalseProb(double limit){
//std::cout << k <<std::endl;
limit = limit - randZeroToOne();
if(limit > 0) return true;
return false;
}
uint16_t RNG::next(uint16_t a, uint16_t b){
if(a == b) return a;
if(b != 0xFFFF) b++;
return (next(b-a)+a);
}