annotate Random.cpp @ 2493:bd4ada7615ce

Слияние
author Ritor1
date Mon, 15 Sep 2014 17:30:29 +0600
parents f4af3b203f65
children
rev   line source
2415
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2334
diff changeset
1 #define _CRTDBG_MAP_ALLOC
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2334
diff changeset
2 #include <stdlib.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2334
diff changeset
3 #include <crtdbg.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2334
diff changeset
4
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
5 #define _CRT_SECURE_NO_WARNINGS
0
Ritor1
parents:
diff changeset
6 #include <math.h>
Ritor1
parents:
diff changeset
7
Ritor1
parents:
diff changeset
8 #include "Random.h"
2037
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1262
diff changeset
9 #include "OurMath.h"
0
Ritor1
parents:
diff changeset
10
Ritor1
parents:
diff changeset
11
Ritor1
parents:
diff changeset
12
Ritor1
parents:
diff changeset
13
780
93c6b78abf35 Random uninitalized fixed
zipi
parents: 0
diff changeset
14 struct Random *pRnd=new Random(); // idb
0
Ritor1
parents:
diff changeset
15
Ritor1
parents:
diff changeset
16
Ritor1
parents:
diff changeset
17
Ritor1
parents:
diff changeset
18
Ritor1
parents:
diff changeset
19
Ritor1
parents:
diff changeset
20 //----- (004BE59E) --------------------------------------------------------
Ritor1
parents:
diff changeset
21 void Random::SetRange(int min, int max)
Ritor1
parents:
diff changeset
22 {
Ritor1
parents:
diff changeset
23 this->min = min;
Ritor1
parents:
diff changeset
24 this->range = max - min;
Ritor1
parents:
diff changeset
25 }
Ritor1
parents:
diff changeset
26
Ritor1
parents:
diff changeset
27 //----- (004BE5B1) --------------------------------------------------------
Ritor1
parents:
diff changeset
28 double Random::GetRandom()
Ritor1
parents:
diff changeset
29 {
Ritor1
parents:
diff changeset
30 Random *v1; // esi@1
Ritor1
parents:
diff changeset
31 double v2; // st7@1
Ritor1
parents:
diff changeset
32 double v3; // st7@1
Ritor1
parents:
diff changeset
33
Ritor1
parents:
diff changeset
34 v1 = this;
Ritor1
parents:
diff changeset
35 this->field_0[3] = this->field_0[2];
Ritor1
parents:
diff changeset
36 this->field_0[2] = this->field_0[1];
Ritor1
parents:
diff changeset
37 v2 = this->field_0[0];
Ritor1
parents:
diff changeset
38 this->field_0[1] = v2;
Ritor1
parents:
diff changeset
39 v3 = this->field_0[3] * 1492.0
Ritor1
parents:
diff changeset
40 + this->field_0[2] * 1776.0
Ritor1
parents:
diff changeset
41 + this->field_0[3] * 2111111111.0
Ritor1
parents:
diff changeset
42 + v2 * 5115.0
Ritor1
parents:
diff changeset
43 + this->field_0[4];
Ritor1
parents:
diff changeset
44 v1->field_0[0] = v3 - floor(v3);
2196
628a0ad87136 Some more PVS error fixing
Grumpy7
parents: 2037
diff changeset
45 v1->field_0[4] = floor(v3) * 2.328306436538696e-10;
628a0ad87136 Some more PVS error fixing
Grumpy7
parents: 2037
diff changeset
46 return v1->field_0[0];
0
Ritor1
parents:
diff changeset
47 }
Ritor1
parents:
diff changeset
48
Ritor1
parents:
diff changeset
49 //----- (004BE623) --------------------------------------------------------
Ritor1
parents:
diff changeset
50 int Random::GetInRange()
Ritor1
parents:
diff changeset
51 {
2334
ddb803517a48 unused local variables I commented
Ritor1
parents: 2253
diff changeset
52 // Random *v1; // esi@1
0
Ritor1
parents:
diff changeset
53 float v2; // ST10_4@1
2334
ddb803517a48 unused local variables I commented
Ritor1
parents: 2253
diff changeset
54 // double v3; // ST04_8@1
0
Ritor1
parents:
diff changeset
55 int floored_random; // ecx@1
Ritor1
parents:
diff changeset
56
Ritor1
parents:
diff changeset
57 v2 = GetRandom() * (double)this->range;
1262
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
58 floored_random = bankersRounding(v2);
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
59 if ( floored_random >= this->range )
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
60 floored_random = this->range;
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
61 return floored_random + this->min;
0
Ritor1
parents:
diff changeset
62 }
Ritor1
parents:
diff changeset
63
Ritor1
parents:
diff changeset
64 //----- (004BE65D) --------------------------------------------------------
Ritor1
parents:
diff changeset
65 void Random::Initialize(int seed)
Ritor1
parents:
diff changeset
66 {
Ritor1
parents:
diff changeset
67 int v2; // eax@1
Ritor1
parents:
diff changeset
68 Random *this_; // esi@1
Ritor1
parents:
diff changeset
69 signed int v4; // ecx@3
Ritor1
parents:
diff changeset
70 unsigned int v5; // eax@4
Ritor1
parents:
diff changeset
71 signed int v6; // edi@5
Ritor1
parents:
diff changeset
72
Ritor1
parents:
diff changeset
73 v2 = seed;
Ritor1
parents:
diff changeset
74 this_ = this;
Ritor1
parents:
diff changeset
75 if ( !seed )
Ritor1
parents:
diff changeset
76 v2 = -1;
Ritor1
parents:
diff changeset
77 v4 = 0;
Ritor1
parents:
diff changeset
78 do
Ritor1
parents:
diff changeset
79 {
Ritor1
parents:
diff changeset
80 v5 = (((v2 << 13) ^ (unsigned int)v2) >> 17) ^ (v2 << 13) ^ v2;
Ritor1
parents:
diff changeset
81 v2 = 32 * v5 ^ v5;
Ritor1
parents:
diff changeset
82 this_->field_0[v4++] = (double)(unsigned int)v2 * 2.328306436538696e-10;
Ritor1
parents:
diff changeset
83 }
Ritor1
parents:
diff changeset
84 while ( v4 < 5 );
Ritor1
parents:
diff changeset
85 v6 = 19;
Ritor1
parents:
diff changeset
86 do
Ritor1
parents:
diff changeset
87 {
Ritor1
parents:
diff changeset
88 GetRandom();
Ritor1
parents:
diff changeset
89 --v6;
Ritor1
parents:
diff changeset
90 }
Ritor1
parents:
diff changeset
91 while ( v6 );
Ritor1
parents:
diff changeset
92 }
Ritor1
parents:
diff changeset
93