-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRNGDiff.java
More file actions
205 lines (191 loc) · 9.39 KB
/
RNGDiff.java
File metadata and controls
205 lines (191 loc) · 9.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Calculus;
import Plot.Screen;
import Calculus.MathsContxtLAv0_1.DiffExpr;
import Calculus.MathsContxtLAv0_1.Expression;
import static Calculus.MathsContxtLAv0_1.GetPrimeNumber;
import static Calculus.MathsContxtLAv0_1.MyFuncDiff;
import static Calculus.MathsContxtLAv0_1.MyFuncExpress;
import static Calculus.MathsContxtLAv0_1.MyFuncSimple;
import static Calculus.MathsContxtLAv0_1.PrimeNumber;
import Calculus.MathsContxtLAv0_1.SimpleExpression;
import static Calculus.MathsContxtLAv0_1.eatAll;
import static Calculus.MathsContxtLAv0_1.parse;
import static Calculus.MathsContxtLAv0_1.parseDiff;
import static Calculus.MathsContxtLAv0_1.parseSimple;
import static Calculus.Usage.FormEquation;
import Plot.SSCCE;
import static Plot.SSCCE.frame;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.List;
import javax.swing.ImageIcon;
import java.util.LinkedList;
/**
*
* @author Administrator
*/
public class RNGDiff {
public static Logger log = Logger.getLogger(RNGDiff.class.getName());
public static LinkedList<String> TupleStore;
public static int x = 0, y = 0;
public static String RandomEquation(String a, String c, String RandVar) {
String Exprn = a + " * " + RandVar + "^7" + " + " + RandVar + "^5" + " + " + RandVar + "^2" + " - " + RandVar + " + " + c;
Exprn = eatAll(Exprn, ' ');
return Exprn;
}
public static long RandomDiff(String Exprn, int planeNum, String AlgoName, long Xn, long MgtACoeff, long MgtbCoeff, long Mgtc, long MgtModulus, String TechDiffWithRespTo) {
//Value = (a * Factorial + c) % (FactorialSpread + 1);
Map<String, Double> variables = new HashMap<>();
Map<String, String> variablesDiff = new HashMap<>();
MyFuncExpress();
MyFuncDiff();
MyFuncSimple();
variablesDiff.put(TechDiffWithRespTo, TechDiffWithRespTo);
//log.info("RNGDiff:Expr_LCG_Factorial: Xn=" + Xn + " Basic Simple Exprn=" + Exprn);
SimpleExpression expSimple;
Expression expValue;
String StrexpSimpleExpress = "";
String StrexpDiffExpress = "";
int TechDiffOrder = 1;
long TempXn = 0;
expValue = parse(Exprn, variables, TechDiffWithRespTo);
TempXn = (long) expValue.eval() % (MgtModulus );
long Xnplus1 = TempXn;
for (; (TechDiffOrder < /*MaxOrderOfX*/ 10) && (TempXn == Xnplus1); TechDiffOrder++) {
variables.put(TechDiffWithRespTo, ((double) Xn));
//expSimple = parseSimple(Exprn, variables, variablesDiff, DiffWithRespTo);
//StrexpSimpleExpress = expSimple.SimpleExpr();
//log.info("RNGDiff:Expr_LCG_Factorial: Xn=" + Xn + " Basic Simple Exprn=" + StrexpSimpleExpress);
DiffExpr exp = parseDiff(Exprn, variables, variablesDiff, TechDiffWithRespTo);
StrexpDiffExpress = exp.DiffExpr();
//log.info("RNGDiff:Expr_LCG_Factorial:Result(Diff Equation)(" + TechDiffOrder + " th order)=> " + StrexpDiffExpress);
//expSimple = parseSimple(StrexpDiffExpress, variables, variablesDiff, DiffWithRespTo);
//StrexpSimpleExpress = expSimple.SimpleExpr();
//log.info("RNGDiff:Expr_LCG_Factorial: Xn=" + Xn + " Basic Simple Exprn=" + StrexpSimpleExpress);
expValue = parse(StrexpDiffExpress, variables, TechDiffWithRespTo);
//log.info("RNGDiff:Expr_LCG_Factorial:Result(Value)(x)=" + expValue.eval());
Exprn = StrexpDiffExpress;
if (TechDiffOrder > 1) {
TempXn = Xnplus1;
}
Xnplus1 = (long) (expValue.eval() % (MgtModulus ));
//Xnplus1=(long)(expValue.eval() );
}
//log.warn("RNGDiff:Expr_LCG_Factorial:Depth=" + DiffOrder);
//log.info("RNGDiff:Expr_LCG_Factorial:Exprn=" + Exprn);
//log.info("RNGDiff:Expr_LCG_Factorial:Xn=" + Xn);
//log.info("RNGDiff:Expr_LCG_Factorial:Xnplus1=" + Xnplus1);
return ((long) Xnplus1);
}
public static void main(String... args) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int sizex = (int) screenSize.getHeight();
int sizey = (int) screenSize.getWidth();
SSCCE mySSCCE=new SSCCE(sizex,sizey);
mySSCCE.createAndShowGUI(sizex,sizey);
int dups=0;
int NumEqnChanged=0;
int timeRetry = 5;
long i = 0;
int MgtMaxExponent=37;
log.fatal("RNGDiffTest:main:Plots Random Pixels on the SCCE Screen. Remember to repaint by Maximize & Restore Down Toggle");
TupleStore = new LinkedList<String>();
StoreTuple(x, y);
log.fatal("RNGDiffTest:main:sizex=" + sizex);
log.fatal("RNGDiffTest:main:sizey=" + sizey);
log.fatal("RNGDiffTest:main:Total Pixel=" + (sizex*sizey) );
String TechDiffWithRespTo="Xn";
long PrimeY = PrimeNumber(sizey) ;
String yExprn = FormEquation(y, (long) 41, (long) 5, (long) PrimeY, TechDiffWithRespTo, MgtMaxExponent);
long PrimeX = GetPrimeNumber(sizex,0) ;
String xExprn = FormEquation(x, (long) 41, (long) 5, (long) PrimeX, TechDiffWithRespTo, MgtMaxExponent);
log.fatal("RNGDiffTest:main:xExprn="+xExprn);
log.fatal("RNGDiffTest:main:yExprn="+yExprn);
log.fatal("RNGDiffTest:main:PrimeY=" + PrimeY + " PrimeX=" + PrimeX);
log.fatal("RNGDiffTest:main:Speed is better if we comment all log.info in MathsContxtLAv4_0 !!!");
log.fatal("RNGDiffTest:main:Started !!!");
for (i=0; i < 10000/*(sizex*sizey)*/; i++) {
//log.fatal("RNGDiff:main:x=" + x + " y=" + y + " i=" + i);
//if ((x >= 0) && (x < sizex) && (y >= 0) && (y < sizey)) {
mySSCCE.showPixel(x,y,0xFFFFFF);
// } else {
// log.fatal("RNGDiff:main:NOT Printing");
// }
while (timeRetry > 0) {
//yExprn = FormEquation(y, (long) 37.0, (long) 5.0, (long) 17.0, "Xn", (int) 7);
double temp = (int) RandomDiff(yExprn, 0, "main", (long) y, (long) 37.0, (long) 17.0, (long) 5.0, PrimeY, TechDiffWithRespTo);
//Mapping "-RND 0 RND" to "0 RND"
if (temp < 0) {
temp = (-1.0) * temp;
}
//0 to RND
if ((temp >= 0) && (temp < sizey)) {
y = (int) temp;
} else {
y = ((int) temp % (sizey + 1));
}
//log.warn("RNGDiff:main:y:temp=" + temp);
//log.warn("RNGDiff:main:y=" + y);
//xExprn = FormEquation(x, (long) 17.0, (long) 5.0, (long) 17.0, "Xn", (int) 7);
temp = (int) RandomDiff(xExprn, 0, "main", (long) x, (long) 17.0, (long) 17.0, (long) 5.0, PrimeX,TechDiffWithRespTo);
//Mapping "-RND 0 RND" to "0 RND"
if (temp < 0) {
temp = (-1.0) * temp;
}
//0 to RND
if ((temp >= 0) && (temp < sizex)) {
x = (int) temp;
} else {
x = ((int) temp % (sizex + 1));
}
//log.warn("RNGDiff:main:x:temp=" + temp);
//log.warn("RNGDiff:main:x=" + x);
if (StoreTuple(x, y)) {
timeRetry = 5;
break;
} else {
log.fatal("RNGDiffTest:main:Found Same Tuple: x=" + x + " y=" + y + " dups=" + (++dups) + " i=" + i + " timeRetry=" + timeRetry );
//String Temp = TupleStore.getLast();
//String[] TempData = Temp.split("@");
//if (TempData.length >= 2) {
// x = (int) Integer.parseInt(TempData[0]);
// y = (int) Integer.parseInt(TempData[1]);
x++;
y++;
//}
log.fatal("RNGDiffTest:main:Changing to Tuple: x=" + x + " y=" + y);
timeRetry--;
continue;
}
}
if(timeRetry==0) {
MgtMaxExponent+=2;
NumEqnChanged++;
yExprn = FormEquation(y, (long) 41.0, (long) 5.0, (long) PrimeY, TechDiffWithRespTo, MgtMaxExponent);
xExprn = FormEquation(x, (long) 41.0, (long) 5.0, (long) PrimeX, TechDiffWithRespTo, MgtMaxExponent);
timeRetry=5;
log.fatal("RNGDiffTest:main:Changed Equation:xExprn="+xExprn);
log.fatal("RNGDiffTest:main:Changed Equation:yExprn="+yExprn);
log.fatal("RNGDiffTest:main:Changed Equation: NumEqnChanged=" + NumEqnChanged);
}
}
log.fatal("RNGDiffTest:main:Finished !!! Total Pixel="+i);
}
public static boolean StoreTuple(long x, long y) {
if (TupleStore.contains(x + "@" + y)) {
return false;
} else {
TupleStore.add(x + "@" + y);
}
return true;
}
}