Mercurial > mm7
annotate Random.cpp @ 2261:236d8d7c7295
Fixing a bug in tokenization
author | Grumpy7 |
---|---|
date | Sat, 08 Mar 2014 16:04:44 +0100 |
parents | aff7a7b072b7 |
children | ddb803517a48 |
rev | line source |
---|---|
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2196
diff
changeset
|
1 #define _CRT_SECURE_NO_WARNINGS |
0 | 2 #include <math.h> |
3 | |
4 #include "Random.h" | |
2037
7a9477135943
Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents:
1262
diff
changeset
|
5 #include "OurMath.h" |
0 | 6 |
7 | |
8 | |
9 | |
780 | 10 struct Random *pRnd=new Random(); // idb |
0 | 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); | |
2196 | 41 v1->field_0[4] = floor(v3) * 2.328306436538696e-10; |
42 return v1->field_0[0]; | |
0 | 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 v2 = GetRandom() * (double)this->range; | |
1262 | 54 floored_random = bankersRounding(v2); |
55 if ( floored_random >= this->range ) | |
56 floored_random = this->range; | |
57 return floored_random + this->min; | |
0 | 58 } |
59 | |
60 //----- (004BE65D) -------------------------------------------------------- | |
61 void Random::Initialize(int seed) | |
62 { | |
63 int v2; // eax@1 | |
64 Random *this_; // esi@1 | |
65 signed int v4; // ecx@3 | |
66 unsigned int v5; // eax@4 | |
67 signed int v6; // edi@5 | |
68 | |
69 v2 = seed; | |
70 this_ = this; | |
71 if ( !seed ) | |
72 v2 = -1; | |
73 v4 = 0; | |
74 do | |
75 { | |
76 v5 = (((v2 << 13) ^ (unsigned int)v2) >> 17) ^ (v2 << 13) ^ v2; | |
77 v2 = 32 * v5 ^ v5; | |
78 this_->field_0[v4++] = (double)(unsigned int)v2 * 2.328306436538696e-10; | |
79 } | |
80 while ( v4 < 5 ); | |
81 v6 = 19; | |
82 do | |
83 { | |
84 GetRandom(); | |
85 --v6; | |
86 } | |
87 while ( v6 ); | |
88 } | |
89 |