1 | #include <stdlib.h> |
---|---|
2 | #include "random.hpp" |
3 | |
4 | static |
5 | void |
6 | init_srand(void) |
7 | { |
8 | static bool inited(false); |
9 | if (!inited) |
10 | { |
11 | inited = true; |
12 | srand(0); |
13 | } |
14 | } |
15 | |
16 | |
17 | float |
18 | random_value(float pmin, float pmax) |
19 | { |
20 | int v; |
21 | float r; |
22 | |
23 | init_srand(); |
24 | v = rand(); |
25 | r = static_cast<float>(v) / static_cast<float>(RAND_MAX); |
26 | return pmin + r * (pmax - pmin); |
27 | } |
28 |