Due to some uncontrollable factors, such as system memory, computer status, and so on, each time in the while loop to perform a certain number of times there will be a difference
About hundreds of times. This leads to a difference in results.
Note that this program uses a number of static variables, that is, when the next thread continues to execute the same run method as the previous thread, its initial value is the value of the previous thread's execution, which forms the classic butterfly effect by amplifying the difference, resulting in the final random number.
In this program, a total of 13 thread threads are opened, and each time the values of those static variables are driven in a confusing direction,
So the end gets the array double[] BB's chaotic degree geometry rises,
The first bb[0] has only about hundreds of possible values, and to bb[3] can be any of the 65,536 data.
To be random, I cycled 13 times, bb[12] almost absolutely random.
Copy Code code as follows:
/**
* Author:yuanhonglong
* Date:2014-1-9
*/
public class Myrandom implements runnable{
private static int random;
private static int f=127;
private static int m= (int) Math.pow (2,16);
private static int[] R=getr ();
private static int x=13;
@Override
public void Run () {
for (;! Thread.interrupted ();) {
F= ((F/2) +r[f])%m;
RANDOM=R[F];
}
}
private static int[] Getr () {
Deposit 0-65536 of these 65,536 numbers in r[in a certain order
Int[] R=new int[m];
r[0]=13849;
for (int i=1;i<m;i++) {
R[i]= ((2053*r[i-1]) +13849)%m;
}
int k=r[65535];
r[65535]=r[(f+1)%m];
r[(f+1)%m]=k;
return R;
}
private static void Changer (int[] r,int f) {
Move to r[]
Int[] R1=new int[r.length];
System.arraycopy (r,0,r1,0,r.length);
for (int i=0;i<r.length;i++) {
r[i]=r1[(i+f)%m];
}
}
public static double Getrandom_0_1 () {
Double[] Dd=new double[13];
for (int i=0;i<dd.length;i++) {
Runnable runnable=new myrandom ();
Thread thread=new thread (runnable);
Thread.Start ();
try{
Thread.Sleep (x+1);
}
catch (Interruptedexception e) {
E.getmessage ();
}
Thread.Interrupt ();
Double rr= (double) random/(double) m;
x=f%13;
Changer (r,11+ (F/7));
DD[I]=RR;
if ((i>0) && (Dd[i]==dd[i-1])) {
Changer (r,13+ (F/11));
Prevent fixed point to the effect of the program, when two values of the same description program may enter a dead end, that is, fixed point, on the fixed point of the problem can refer to advanced mathematics on the function of knowledge
}
}
Double ran=dd[12];
return ran;
}
public static void Main (string[] args) {
Double Rs=getrandom_0_1 ();
System.out.println (RS);
}
}
Myrandom.java
Copy Code code as follows:
/**
* Author:yuanhonglong
* Date:2014-1-9
*/
Package mine.loop;
public class Myrandom implements runnable{
private static int random;
private static int f=127;
private static int m= (int) Math.pow (2,16);
private static int[] R=getr ();
private static int x=13;
@Override
public void Run () {
for (;! Thread.interrupted ();) {
F= ((F/2) +r[f])%m;
RANDOM=R[F];
}
}
private static int[] Getr () {
Deposit 0-65536 of these 65,536 numbers in r[in a certain order
Int[] R=new int[m];
r[0]=13849;
for (int i=1;i<m;i++) {
R[i]= ((2053*r[i-1]) +13849)%m;
}
int k=r[65535];
r[65535]=r[(f+1)%m];
r[(f+1)%m]=k;
return R;
}
private static void Changer (int[] r,int f) {
Int[] R1=new int[r.length];
System.arraycopy (r,0,r1,0,r.length);
for (int i=0;i<r.length;i++) {
r[i]=r1[(i+f)%m];
}
}
public static double Getrandom_0_1 () {
Double[] Dd=new double[13];
for (int i=0;i<dd.length;i++) {
Runnable runnable=new myrandom ();
Thread thread=new thread (runnable);
Thread.Start ();
try{
Thread.Sleep (x+1);
}
catch (Interruptedexception e) {
E.getmessage ();
}
Thread.Interrupt ();
Double rr= (double) random/(double) m;
x=f%13;
Changer (r,11+ (F/7));
DD[I]=RR;
if ((i>0) && (Dd[i]==dd[i-1])) {
Changer (r,13+ (F/11));
Prevent fixed point to the effect of the program, when two values of the same description program may enter a dead end, that is, fixed point, on the fixed point of the problem can refer to advanced mathematics on the function of knowledge
}
}
Double ran=dd[12];
return ran;
}
public static void Main (string[] args) {
Double Rs=getrandom_0_1 ();
System.out.println (RS);
}
}