On Monday, 14 July 2014 at 22:21:36 UTC, bearophile wrote:
Nordlöw:
Is there a natural way of generating/filling a
string/wstring/dstring of a specific length with random
contents?
Do you mean something like this?
import std.stdio, std.random, std.ascii, std.range, std.conv;
string genRandomString(in size_t len) {
return len
.iota
.map!(_ => lowercase[uniform(0, $)])
.text;
}
void main() {
import std.stdio;
10.genRandomString.writeln;
}
Bye,
bearophile
Alternative:
randomSample(lowercase, 10, lowercase.length).writeln;