Mercurial > mm7
annotate Random.cpp @ 2209:3664342f5d93
DrawCardsRectangles continue
author | Ritor1 |
---|---|
date | Wed, 12 Feb 2014 17:32:47 +0600 |
parents | 628a0ad87136 |
children | aff7a7b072b7 |
rev | line source |
---|---|
0 | 1 #include <math.h> |
2 | |
3 #include "Random.h" | |
2037
7a9477135943
Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents:
1262
diff
changeset
|
4 #include "OurMath.h" |
0 | 5 |
6 | |
7 | |
8 | |
780 | 9 struct Random *pRnd=new Random(); // idb |
0 | 10 |
11 | |
12 | |
13 | |
14 | |
15 //----- (004BE59E) -------------------------------------------------------- | |
16 void Random::SetRange(int min, int max) | |
17 { | |
18 this->min = min; | |
19 this->range = max - min; | |
20 } | |
21 | |
22 //----- (004BE5B1) -------------------------------------------------------- | |
23 double Random::GetRandom() | |
24 { | |
25 Random *v1; // esi@1 | |
26 double v2; // st7@1 | |
27 double v3; // st7@1 | |
28 | |
29 v1 = this; | |
30 this->field_0[3] = this->field_0[2]; | |
31 this->field_0[2] = this->field_0[1]; | |
32 v2 = this->field_0[0]; | |
33 this->field_0[1] = v2; | |
34 v3 = this->field_0[3] * 1492.0 | |
35 + this->field_0[2] * 1776.0 | |
36 + this->field_0[3] * 2111111111.0 | |
37 + v2 * 5115.0 | |
38 + this->field_0[4]; | |
39 v1->field_0[0] = v3 - floor(v3); | |
2196 | 40 v1->field_0[4] = floor(v3) * 2.328306436538696e-10; |
41 return v1->field_0[0]; | |
0 | 42 } |
43 | |
44 //----- (004BE623) -------------------------------------------------------- | |
45 int Random::GetInRange() | |
46 { | |
47 Random *v1; // esi@1 | |
48 float v2; // ST10_4@1 | |
49 double v3; // ST04_8@1 | |
50 int floored_random; // ecx@1 | |
51 | |
52 v2 = GetRandom() * (double)this->range; | |
1262 | 53 floored_random = bankersRounding(v2); |
54 if ( floored_random >= this->range ) | |
55 floored_random = this->range; | |
56 return floored_random + this->min; | |
0 | 57 } |
58 | |
59 //----- (004BE65D) -------------------------------------------------------- | |
60 void Random::Initialize(int seed) | |
61 { | |
62 int v2; // eax@1 | |
63 Random *this_; // esi@1 | |
64 signed int v4; // ecx@3 | |
65 unsigned int v5; // eax@4 | |
66 signed int v6; // edi@5 | |
67 | |
68 v2 = seed; | |
69 this_ = this; | |
70 if ( !seed ) | |
71 v2 = -1; | |
72 v4 = 0; | |
73 do | |
74 { | |
75 v5 = (((v2 << 13) ^ (unsigned int)v2) >> 17) ^ (v2 << 13) ^ v2; | |
76 v2 = 32 * v5 ^ v5; | |
77 this_->field_0[v4++] = (double)(unsigned int)v2 * 2.328306436538696e-10; | |
78 } | |
79 while ( v4 < 5 ); | |
80 v6 = 19; | |
81 do | |
82 { | |
83 GetRandom(); | |
84 --v6; | |
85 } | |
86 while ( v6 ); | |
87 } | |
88 |