Generating Strings with Random Contents
"Nordlöw" via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 14 15:32:49 PDT 2014
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
I was specifically interested in something that exercises (random
samples) potentially _all_ code points for string, wstring and
dstring (all code units that is).
More information about the Digitalmars-d-learn
mailing list