Too complicated code for generating a random string?
greenbyte
lysenko765 at yandex.ru
Fri Jun 17 17:16:12 UTC 2022
On Saturday, 23 February 2013 at 01:07:23 UTC, bearophile wrote:
>
> So it becomes something like:
>
> 10.table!({ return letters.choice; }).writeln;
>
Dear bearophile, without the table() function in the standard
library, this code does not work.
After hours, I managed to write code to generate random strings
based on your code.
```d
import std.array : array;
import std.ascii : letters, digits;
import std.random : choice, Random, unpredictableSeed;
import std.range : generate, take;
import std.stdio : writeln;
auto rnd = Random(unpredictableSeed);
auto symbols = array(letters ~ digits);
generate!({ return symbols.choice(rnd); }).take(10).writeln;
```
More information about the Digitalmars-d
mailing list