Skip to content

Instantly share code, notes, and snippets.

@gmfc
Created May 22, 2013 22:11
Show Gist options
  • Select an option

  • Save gmfc/5631364 to your computer and use it in GitHub Desktop.

Select an option

Save gmfc/5631364 to your computer and use it in GitHub Desktop.
import javax.swing.*;
import java.io.FileWriter;
import java.io.IOException;
public class rand {
public static void main(String[] args) {
//Xf=(a*Xi+b)%m;
double a = 752395;
double Xi;
double m = 254;
double b = 25;
double Xf;
double i;
Xi=entrada("Xi");
i=entrada("Quantos números serão gerados?");
try{
FileWriter writer = new FileWriter("c:\\test.csv");
for(int cont = 1;cont<=i;cont++){
Xf=(a*Xi+b)%m;
Xi=Xf;
writer.append(cont + "");
writer.append(',');
writer.append(Xf + "");
writer.append("\n");
//JOptionPane.showMessageDialog(null, Xf);
}
writer.flush();
writer.close();
}
catch(IOException e){
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Pronto! arquivo c: test.csv criado!");
}
public static double entrada(String var){
double ent;
ent = Double.parseDouble(JOptionPane.showInputDialog("entre com o valor de +"+var));
return ent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment