std.random suggestions

Denis Feklushkin feklushkin.denis at gmail.com
Fri Sep 19 16:38:59 UTC 2025


On Thursday, 18 September 2025 at 12:53:25 UTC, IchorDev wrote:

>> literature). Everything else is plain overengineering and 
>> deserves to be written in 3rd party library by these willing 
>> to pursue it.
>
> Agreed. If anything, std.random is very well designed because 
> it uses the range interface in a clever way.

Range interface is not unique to `std.random`. Same template 
patterns are possible in any other implementation.

[I already made 
code](https://github.com/denizzzka/misc/tree/master/random) which 
I described in the main post. This is how I propose generate 
randoms using ranges:
```d
     int[] iarr = generate!(() => rndGen!int).take(5).array;

```
`rndGen` is helper template, it calls random generation for each 
range element. In my opinion, there's no difference in use such 
ranges with `std.random`.

In addition, you also get access to basic functions for 
generating cryptographically secure random sequences without 
overhead and with lower possibility of screwing up with its 
calling:
```d
     ubyte[24] buf;

     getSeededRandomBlocking(buf);
```
It's very simple, yes. I think the last line covers 95% of all 
needings.

(And I hope someone will ask why this function is called this way)



More information about the Digitalmars-d mailing list