fork(3) download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. public static String comboFrom(String possibleChars, int charsToTake) {
  7. //randomly shuffle the chars using Collections.shuffle
  8. List<Character> chars = new ArrayList<Character>(possibleChars.length());
  9. for (char c : possibleChars.toCharArray()) {
  10. chars.add(new Character(c));
  11. }
  12. Collections.shuffle(chars);
  13. String result = "";
  14. //Take the first 'charsToTake' characters - these will be totally random
  15. //thanks to the shuffle
  16. int taken=0;
  17. for (Character c : chars) {
  18. result += c.charValue();
  19. if (taken >= charsToTake) break;
  20. taken += 1;
  21. }
  22. return result;
  23. }
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. for (int i=0; i < 30; i++) {
  27. System.out.println(comboFrom("abcdefghijkl@#%", 5));
  28. }
  29. }
  30. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
ecjlaf
bi@hfj
ia@#e%
icfad@
kb#gei
ik%@de
ib%jkf
flgb@#
gd@ekc
jedhi#
f@%ckj
lig%#j
l%fki#
ajgdlc
adkbe@
gb@cid
#efcag
@lihkc
k@j%#c
cgkaji
ecb@hj
k@lf%a
gd%fbh
c%lajf
e@#cid
%gfeb#
#%ahcf
be@flj
albjk@
calh%g