Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Last active August 29, 2015 13:59
Show Gist options
  • Save JorgeOlvera/10441069 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/10441069 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
public class RandomIntegerData {
public static void main(String [] args) throws IOException {
Scanner input = new Scanner(System.in);
Random randomnum = new Random();
System.out.println("Enter highest value ");
int highvalue = input.nextInt();
System.out.println("Enter # of integers per line ");
int perline = input.nextInt();
System.out.println("Enter the total number of integers ");
int tCount = input.nextInt();
System.out.println("Enter the file name ");
String filename = input.next();
try{
PrintWriter outputFile = new PrintWriter(
new BufferedWriter(
new FileWriter(filename)));
int cell = 0;
while(cell<tCount){
for(int a=0; a<perline; a++) {
int num = randomnum.nextInt(highvalue);
outputFile.print(num + " ");
cell++;
}
outputFile.print("\n");
}
outputFile.close();
} catch (IOException e){
System.err.println("IOException @" + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment