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