annotate Random.cpp @ 105:e633cde38d64

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