import alg = std.algorithm;
import std.stdio;
import std.string;
import std.conv;
import std.random;
void main() {
auto name = Name(6);
auto names = new string[25];
alg.fill(names[], name);
foreach(n; names)
writeln(n);
}
struct Name {
string current;
uint wordSize;
typeof(Random(unpredictableSeed)) rnd;
this(uint size) {
wordSize = size;
rnd = Random(unpredictableSeed);
popFront();
}
// We never run out of names
@property enum bool empty = false;
// Obtain the current name
@property string front() {
return current;
}
// Build the next name which we get with front
void popFront() {
auto newWord = new dchar[wordSize];
// Fill the array with random lowercase letters
alg.fill(newWord[], randomCover(lowercase[], rnd));
// I think there is a bug here, since rnd ends up being a
// copied Random, calling popFront randomly generates the
// same random word.
rnd = Random(unpredictableSeed);
// Store it as a string
current = to!string(newWord);
}
auto save() { return this; }
}
aW1wb3J0IGFsZyA9IHN0ZC5hbGdvcml0aG07CmltcG9ydCBzdGQuc3RkaW87CmltcG9ydCBzdGQuc3RyaW5nOwppbXBvcnQgc3RkLmNvbnY7CmltcG9ydCBzdGQucmFuZG9tOwoKdm9pZCBtYWluKCkgewoJYXV0byBuYW1lID0gTmFtZSg2KTsgCgoJYXV0byBuYW1lcyA9IG5ldyBzdHJpbmdbMjVdOwoKCWFsZy5maWxsKG5hbWVzW10sIG5hbWUpOwoKCWZvcmVhY2gobjsgbmFtZXMpCgkJd3JpdGVsbihuKTsKfQoKCnN0cnVjdCBOYW1lIHsKCXN0cmluZyBjdXJyZW50OwoJdWludCB3b3JkU2l6ZTsKCXR5cGVvZihSYW5kb20odW5wcmVkaWN0YWJsZVNlZWQpKSBybmQ7CgoJdGhpcyh1aW50IHNpemUpIHsKCQl3b3JkU2l6ZSA9IHNpemU7CgkJcm5kID0gUmFuZG9tKHVucHJlZGljdGFibGVTZWVkKTsKCgkJcG9wRnJvbnQoKTsKCX0KCgkvLyBXZSBuZXZlciBydW4gb3V0IG9mIG5hbWVzCglAcHJvcGVydHkgZW51bSBib29sIGVtcHR5ID0gZmFsc2U7CgoJLy8gT2J0YWluIHRoZSBjdXJyZW50I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