2499
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6 #include <math.h>
|
|
7
|
|
8 #include "Random.h"
|
|
9 #include "OurMath.h"
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14 struct Random *pRnd=new Random(); // idb
|
|
15
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20 //----- (004BE59E) --------------------------------------------------------
|
|
21 void Random::SetRange(int min, int max)
|
|
22 {
|
|
23 this->min = min;
|
|
24 this->range = max - min;
|
|
25 }
|
|
26
|
|
27 //----- (004BE5B1) --------------------------------------------------------
|
|
28 double Random::GetRandom()
|
|
29 {
|
|
30 Random *v1; // esi@1
|
|
31 double v2; // st7@1
|
|
32 double v3; // st7@1
|
|
33
|
|
34 v1 = this;
|
|
35 this->field_0[3] = this->field_0[2];
|
|
36 this->field_0[2] = this->field_0[1];
|
|
37 v2 = this->field_0[0];
|
|
38 this->field_0[1] = v2;
|
|
39 v3 = this->field_0[3] * 1492.0
|
|
40 + this->field_0[2] * 1776.0
|
|
41 + this->field_0[3] * 2111111111.0
|
|
42 + v2 * 5115.0
|
|
43 + this->field_0[4];
|
|
44 v1->field_0[0] = v3 - floor(v3);
|
|
45 v1->field_0[4] = floor(v3) * 2.328306436538696e-10;
|
|
46 return v1->field_0[0];
|
|
47 }
|
|
48
|
|
49 //----- (004BE623) --------------------------------------------------------
|
|
50 int Random::GetInRange()
|
|
51 {
|
|
52 // Random *v1; // esi@1
|
|
53 float v2; // ST10_4@1
|
|
54 // double v3; // ST04_8@1
|
|
55 int floored_random; // ecx@1
|
|
56
|
|
57 v2 = GetRandom() * (double)this->range;
|
|
58 floored_random = bankersRounding(v2);
|
|
59 if ( floored_random >= this->range )
|
|
60 floored_random = this->range;
|
|
61 return floored_random + this->min;
|
|
62 }
|
|
63
|
|
64 //----- (004BE65D) --------------------------------------------------------
|
|
65 void Random::Initialize(int seed)
|
|
66 {
|
|
67 int v2; // eax@1
|
|
68 Random *this_; // esi@1
|
|
69 signed int v4; // ecx@3
|
|
70 unsigned int v5; // eax@4
|
|
71 signed int v6; // edi@5
|
|
72
|
|
73 v2 = seed;
|
|
74 this_ = this;
|
|
75 if ( !seed )
|
|
76 v2 = -1;
|
|
77 v4 = 0;
|
|
78 do
|
|
79 {
|
|
80 v5 = (((v2 << 13) ^ (unsigned int)v2) >> 17) ^ (v2 << 13) ^ v2;
|
|
81 v2 = 32 * v5 ^ v5;
|
|
82 this_->field_0[v4++] = (double)(unsigned int)v2 * 2.328306436538696e-10;
|
|
83 }
|
|
84 while ( v4 < 5 );
|
|
85 v6 = 19;
|
|
86 do
|
|
87 {
|
|
88 GetRandom();
|
|
89 --v6;
|
|
90 }
|
|
91 while ( v6 );
|
|
92 }
|
|
93
|