-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx_probability.hpp
49 lines (42 loc) · 1.01 KB
/
x_probability.hpp
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
47
48
49
//
// x_probability.hpp
// x
//
// Created by Daher Alfawares on 1/26/18.
// Copyright © 2018 Daher Alfawares. All rights reserved.
//
#ifndef x_probability_hpp
#define x_probability_hpp
#include <vector>
namespace x {
class probability {
float normal;
public:
probability()
{
this->normal = 0;
}
probability(float normal)
{
this->normal = normal;
}
operator bool() const {
float random = std::rand() / static_cast<float>(RAND_MAX);
return random <= this->normal;
}
probability& operator = (float value){
normal = value;
return *this;
}
float value() const {
return normal;
}
};
}
#include <ostream>
inline
std::ostream & operator << (std::ostream& stream, const x::probability& probability){
return stream << probability.value();
}
#include "x_test_probability.hpp"
#endif /* x_probability_hpp */