fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static Random random = new Random();
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Map<Integer, Integer> counter = new HashMap<Integer, Integer>();
  14. random.setSeed(System.nanoTime());
  15. for (int i = 0; i < 10000000; i++) {
  16. int key = random.nextInt(7) + 1;
  17. Integer val = counter.get(key);
  18. if (null == val)
  19. val = 0;
  20. val++;
  21. counter.put(key, val);
  22. }
  23. for (Map.Entry<Integer, Integer> entry : counter.entrySet()) {
  24. System.out.println(entry.getKey() + ": " + entry.getValue());
  25. }
  26. }
  27. }
Success #stdin #stdout 1.28s 320320KB
stdin
Standard input is empty
stdout
1: 1427164
2: 1429171
3: 1428642
4: 1428566
5: 1429949
6: 1428424
7: 1428084