annotate Random.cpp @ 1303:dcc52e17b517

m
author Ritor1
date Sun, 23 Jun 2013 14:02:07 +0600
parents 0aeac0b9ca30
children 7a9477135943
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"
1262
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
4 #include "Math.h"
0
Ritor1
parents:
diff changeset
5
Ritor1
parents:
diff changeset
6
Ritor1
parents:
diff changeset
7
Ritor1
parents:
diff changeset
8
780
93c6b78abf35 Random uninitalized fixed
zipi
parents: 0
diff changeset
9 struct Random *pRnd=new Random(); // idb
0
Ritor1
parents:
diff changeset
10
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 //----- (004BE59E) --------------------------------------------------------
Ritor1
parents:
diff changeset
16 void Random::SetRange(int min, int max)
Ritor1
parents:
diff changeset
17 {
Ritor1
parents:
diff changeset
18 this->min = min;
Ritor1
parents:
diff changeset
19 this->range = max - min;
Ritor1
parents:
diff changeset
20 }
Ritor1
parents:
diff changeset
21
Ritor1
parents:
diff changeset
22 //----- (004BE5B1) --------------------------------------------------------
Ritor1
parents:
diff changeset
23 double Random::GetRandom()
Ritor1
parents:
diff changeset
24 {
Ritor1
parents:
diff changeset
25 Random *v1; // esi@1
Ritor1
parents:
diff changeset
26 double v2; // st7@1
Ritor1
parents:
diff changeset
27 double v3; // st7@1
Ritor1
parents:
diff changeset
28
Ritor1
parents:
diff changeset
29 v1 = this;
Ritor1
parents:
diff changeset
30 this->field_0[3] = this->field_0[2];
Ritor1
parents:
diff changeset
31 this->field_0[2] = this->field_0[1];
Ritor1
parents:
diff changeset
32 v2 = this->field_0[0];
Ritor1
parents:
diff changeset
33 this->field_0[1] = v2;
Ritor1
parents:
diff changeset
34 v3 = this->field_0[3] * 1492.0
Ritor1
parents:
diff changeset
35 + this->field_0[2] * 1776.0
Ritor1
parents:
diff changeset
36 + this->field_0[3] * 2111111111.0
Ritor1
parents:
diff changeset
37 + v2 * 5115.0
Ritor1
parents:
diff changeset
38 + this->field_0[4];
Ritor1
parents:
diff changeset
39 v1->field_0[0] = v3 - floor(v3);
Ritor1
parents:
diff changeset
40 v1->field_0[4] = v3 * 2.328306436538696e-10;
Ritor1
parents:
diff changeset
41 return v3 - v3;
Ritor1
parents:
diff changeset
42 }
Ritor1
parents:
diff changeset
43
Ritor1
parents:
diff changeset
44 //----- (004BE623) --------------------------------------------------------
Ritor1
parents:
diff changeset
45 int Random::GetInRange()
Ritor1
parents:
diff changeset
46 {
Ritor1
parents:
diff changeset
47 Random *v1; // esi@1
Ritor1
parents:
diff changeset
48 float v2; // ST10_4@1
Ritor1
parents:
diff changeset
49 double v3; // ST04_8@1
Ritor1
parents:
diff changeset
50 int floored_random; // ecx@1
Ritor1
parents:
diff changeset
51
Ritor1
parents:
diff changeset
52 v2 = GetRandom() * (double)this->range;
1262
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
53 floored_random = bankersRounding(v2);
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
54 if ( floored_random >= this->range )
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
55 floored_random = this->range;
0aeac0b9ca30 included header cleanup
Grumpy7
parents: 780
diff changeset
56 return floored_random + this->min;
0
Ritor1
parents:
diff changeset
57 }
Ritor1
parents:
diff changeset
58
Ritor1
parents:
diff changeset
59 //----- (004BE65D) --------------------------------------------------------
Ritor1
parents:
diff changeset
60 void Random::Initialize(int seed)
Ritor1
parents:
diff changeset
61 {
Ritor1
parents:
diff changeset
62 int v2; // eax@1
Ritor1
parents:
diff changeset
63 Random *this_; // esi@1
Ritor1
parents:
diff changeset
64 signed int v4; // ecx@3
Ritor1
parents:
diff changeset
65 unsigned int v5; // eax@4
Ritor1
parents:
diff changeset
66 signed int v6; // edi@5
Ritor1
parents:
diff changeset
67
Ritor1
parents:
diff changeset
68 v2 = seed;
Ritor1
parents:
diff changeset
69 this_ = this;
Ritor1
parents:
diff changeset
70 if ( !seed )
Ritor1
parents:
diff changeset
71 v2 = -1;
Ritor1
parents:
diff changeset
72 v4 = 0;
Ritor1
parents:
diff changeset
73 do
Ritor1
parents:
diff changeset
74 {
Ritor1
parents:
diff changeset
75 v5 = (((v2 << 13) ^ (unsigned int)v2) >> 17) ^ (v2 << 13) ^ v2;
Ritor1
parents:
diff changeset
76 v2 = 32 * v5 ^ v5;
Ritor1
parents:
diff changeset
77 this_->field_0[v4++] = (double)(unsigned int)v2 * 2.328306436538696e-10;
Ritor1
parents:
diff changeset
78 }
Ritor1
parents:
diff changeset
79 while ( v4 < 5 );
Ritor1
parents:
diff changeset
80 v6 = 19;
Ritor1
parents:
diff changeset
81 do
Ritor1
parents:
diff changeset
82 {
Ritor1
parents:
diff changeset
83 GetRandom();
Ritor1
parents:
diff changeset
84 --v6;
Ritor1
parents:
diff changeset
85 }
Ritor1
parents:
diff changeset
86 while ( v6 );
Ritor1
parents:
diff changeset
87 }
Ritor1
parents:
diff changeset
88