annotate Random.cpp @ 654:eb67721c5268

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