fork(2) download
  1. import java.util.Random;
  2.  
  3. class Rawr {
  4. static class Yawn {
  5. StringBuilder b = new StringBuilder();
  6. int groups;
  7. boolean usedKeepYet;
  8. Yawn() {}
  9. void toss() {
  10. System.out.println(b);
  11. }
  12. }
  13. static final String[] constructs =
  14. {"\\s", "\\S", "\\d", "\\D", "\\w", "\\W", "^", "$", "]", "{", "}", "\\b",
  15. "\\B", "\\t", "\\n", "\\r", "\\h", "\\K"};
  16. static final String[] quantifiers = {"*", "+", "?"};
  17. static final String[] groups = {"?:", "?>", "?|", "?#", "?!", "?<!", "?<="};
  18.  
  19. public static void main(String[] args) {
  20. Yawn yawn = new Yawn();
  21. for (Random rand = new Random(); 0 != rand.nextInt(20);)
  22. addWoolTo(yawn, rand);
  23. yawn.toss();
  24. }
  25. static void addWoolTo(Yawn yar, Random wool) {
  26. switch (wool.nextInt(9)) {
  27. case 0:
  28. String thing = constructs[wool.nextInt(constructs.length)];
  29. if (yar.usedKeepYet && ("\\K" == thing)) {
  30. yar.b.append("\\s");
  31. return;
  32. } else if ("\\K" == thing)
  33. yar.usedKeepYet = true;
  34. yar.b.append(thing);
  35. break;
  36. case 1:
  37. case 2: // #FT#
  38. case 3:
  39. yar.b.append((char)
  40. (wool.nextInt(26) + (wool.nextBoolean()? 'a' : 'A')));
  41. break;
  42. case 4:
  43. yar.b.append("|");
  44. yar.usedKeepYet = false;
  45. break;
  46. case 5:
  47. if (wool.nextBoolean()) {
  48. yar.b.append("{" + wool.nextInt(16));
  49. if (wool.nextBoolean())
  50. yar.b.append("," + wool.nextInt(16));
  51. yar.b.append('}');
  52. } else
  53. yar.b.append(quantifiers[wool.nextInt(quantifiers.length)]);
  54. if (wool.nextInt(4) == 0)
  55. yar.b.append(wool.nextBoolean() ? '+' : '?');
  56. break;
  57. case 6:
  58. case 7:
  59. yar.b.append('(');
  60. if ((yar.groups != 0) && wool.nextInt(8) == 0)
  61. yar.b.append("?(" + (1 + wool.nextInt(yar.groups - 1)) +")");
  62. else if (wool.nextInt(3) == 0) {
  63. yar.b.append(groups[wool.nextInt(groups.length)]);
  64. } else yar.groups++;
  65. while (0 != wool.nextInt(4))
  66. addWoolTo(yar, wool);
  67. yar.b.append(')');
  68. break;
  69. case 8:
  70. yar.b.append(wool.nextInt(10));
  71. }
  72. }
  73. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
p(?!)\Wj??L(|)y(?!aggO{0,4}8){2,2}f\h(u3(s\w)\b())(0})3v{15}?7Fum(\w)rO()I(S(F|{5,1}|(?(3)()(?(7)(?(7)\h(?:0))()p(?|({))|xM{2,2}+)()())))UBb(?>\WHUT+F(?:)|A(?#\wh)(?!)N){4}+\d*+FS