A more popular method of generating a random number.Mathematically its somethin like this........
resultant=(a * seed) + (b % c);
According to the original method a,b & c are constants,but here i have taken them as funtions of seed.
f(seed)=a;f(seed)=b;f(seed)=c;
The code..............
resultant=(a * seed) + (b % c);
According to the original method a,b & c are constants,but here i have taken them as funtions of seed.
f(seed)=a;f(seed)=b;f(seed)=c;
The code..............
package Random;
import java.io.*;
public class random {
public static double rand()
{
double seed=0.0,res=0.0,a=0.0,b=0.0,c=0.0;
try{
File f=new File("C:\\Users\\Souvik\\Documents\\NetBeansProjects\\Gojkid\\src\\Random\\db.dat");
/*
* Here mention the path of the database of the seed.
*/
FileInputStream fis=new FileInputStream(f);
DataInputStream dis=new DataInputStream(fis);
seed=dis.readDouble();
a=seed*3;b=seed*13;c=seed*5;
res=(seed*a)+(b%c);
while(res<0.1)
res=res*10;
if(res>1.0)
res=((double)((int)res))-res;
if(res<0)
res=-res;
seed=res;
dis.close();
fis.close();
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dos=new DataOutputStream(fos);
dos.writeDouble(seed);
fos.close();
dos.close();
}
catch(Exception e)
{
System.err.println(e.getMessage());
}
return res;
}
}
1 Comments On This Entry
Page 1 of 1
Page 1 of 1
Recent Entries
-
Implementing Gauss-Elimination Method to solve simultaneous linear equations
on Jun 27 2012 11:19 PM
-
-
-
-
Recent Comments
My Blog Links
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
|
|



1 Comments









|