fork download
  1. import alg = std.algorithm;
  2. import std.stdio;
  3. import std.string;
  4. import std.conv;
  5. import std.random;
  6.  
  7. void main() {
  8. auto name = Name(6);
  9.  
  10. auto names = new string[25];
  11.  
  12. alg.fill(names[], name);
  13.  
  14. foreach(n; names)
  15. writeln(n);
  16. }
  17.  
  18.  
  19. struct Name {
  20. string current;
  21. uint wordSize;
  22. typeof(Random(unpredictableSeed)) rnd;
  23.  
  24. this(uint size) {
  25. wordSize = size;
  26. rnd = Random(unpredictableSeed);
  27.  
  28. popFront();
  29. }
  30.  
  31. // We never run out of names
  32. @property enum bool empty = false;
  33.  
  34. // Obtain the current name
  35. @property string front() {
  36. return current;
  37. }
  38.  
  39. // Build the next name which we get with front
  40. void popFront() {
  41. auto newWord = new dchar[wordSize];
  42.  
  43. // Fill the array with random lowercase letters
  44. alg.fill(newWord[], randomCover(lowercase[], rnd));
  45. // I think there is a bug here, since rnd ends up being a
  46. // copied Random, calling popFront randomly generates the
  47. // same random word.
  48. rnd = Random(unpredictableSeed);
  49.  
  50. // Store it as a string
  51. current = to!string(newWord);
  52. }
  53.  
  54. auto save() { return this; }
  55. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty