Generating Strings with Random Contents
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 14 15:21:35 PDT 2014
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
More information about the Digitalmars-d-learn
mailing list