How to generate a random string ...

Panke via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 17 01:24:27 PDT 2015


On Monday, 16 March 2015 at 13:33:55 UTC, Robert burner Schadek
wrote:
> ... from all Unicode characters in an idiomatic D way? 
> (std.interal.unicode_*)
>
> ```
> T genUnicodeString(T)(size_t minChars, size_t maxChars) 
> if(isSomeString!T) {
>     ...
> }
> ```

You'll need two things. A uniform distribution of { 0 ... 113,020
}, this should be easy using phobos. And a mapping of { 0 ...
113,020 } -> unicode ( or UTFX directly ). Since the unicode
planes or not connected, this might involve some kind of table.

Then just generate your uniform distribution and apply the
mapping.


More information about the Digitalmars-d-learn mailing list