Skip to content

Instantly share code, notes, and snippets.

@kyleburton
Created October 19, 2010 23:29
Show Gist options
  • Save kyleburton/635402 to your computer and use it in GitHub Desktop.
Save kyleburton/635402 to your computer and use it in GitHub Desktop.
public class Main {
public static void main ( String args [] ) {
int size = 392000000;
int sampleSize = 20000;
System.err.println("Start: allocation");
int [] array = new int[size];
System.err.println("Done: allocation");
java.util.Random rnd = new java.util.Random();
System.err.println("Start: population w/line numbers");
for ( int ii = 0; ii < size; ++ii ) {
array[ii] = ii+1;
}
System.err.println("Done: population w/line numbers");
System.err.println("Start: shuffle");
for ( int ii = 0; ii < size; ++ii ) {
int newPos = rnd.nextInt(size);
int tmp = array[ii];
array[ii] = array[newPos];
array[newPos] = tmp;
}
System.err.println("Done: shuffle");
for ( int ii = 0; ii < sampleSize; ++ii ){
System.out.println("" + array[ii]);
}
}
}
// javac Main.java
// time java -Xmx4096M Main > results.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment