srand in D

kdevel kdevel at vogtner.de
Sun Jan 9 10:19:06 UTC 2022


On Sunday, 9 January 2022 at 03:15:02 UTC, Ali Çehreli wrote:
> What would work in the code above is 'choice':
>
>   char q = choice(allowed_chars);
>
> But that hits another fact of D: arrays of chars are strings, 
> which cannot be RandomAccessRange because individual chars must 
> be decoded to form dchars.

One can use explicit index notation which is nearly as compact as 
the template parameter form:

    string salt = iota (0, 16)
       .map!(i => saltchars [uniform(0, $)])
       .array;




More information about the Digitalmars-d-learn mailing list