Skip to content

Instantly share code, notes, and snippets.

@soul0592
Created July 1, 2013 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soul0592/5899368 to your computer and use it in GitHub Desktop.
Save soul0592/5899368 to your computer and use it in GitHub Desktop.
Generador de numeros pseudoaleatorios.
import java.io.*;
public class rand
{
public static void main(String[] args)
{
File a = new File("keyjv.dat");
int largo = Integer.parseInt(args[0]);
int renglon = Integer.parseInt(args[1]);
int uno = 0, cero = 0,random;
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(a));
PrintWriter pw = new PrintWriter(bw);
for(int i = 0; i < renglon; i++)
{
for(int j = 0; j < largo; j++)
{
random = (int)(Math.random()*2);
pw.write(random + "");
if(random == 1)
uno++;
else
cero++;
}
pw.write("\n");
}
pw.write("Cero: "+cero+"\n");
pw.write("Uno: "+uno+"\n");
bw.close();
pw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment