fork download
  1. import java.util.Random;
  2. import java.util.BitSet;
  3.  
  4. class MyProgram {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. long total = 0;
  9. int randomInt;
  10. int count = 100000;
  11. int divider = 3;
  12. Random random = new Random();
  13.  
  14. BitSet bits = new BitSet(count);
  15.  
  16. for(int i=0; i < count; i++){
  17.  
  18. randomInt = random.nextInt(count);
  19.  
  20. // start
  21. int value1 = randomInt / divider;
  22. int value2 = (randomInt % divider != 0) ? 1 : 0;
  23. randomInt = value1 + value2;
  24. // end
  25.  
  26. randomInt = bits.nextClearBit(randomInt);
  27. bits.set(randomInt);
  28.  
  29. total += randomInt;
  30. }
  31.  
  32. System.out.println("Total : " + total);
  33. }
  34. }
  35.  
Success #stdin #stdout 0.16s 711168KB
stdin
Standard input is empty
stdout
Total : 5000049998