The OpenD Programming Language

mir_random_genRandomNonBlocking

Fills a buffer with random data. If not enough entropy has been gathered, it won't block. Hence the error code should be inspected.

On Linux >= 3.17 genRandomNonBlocking is guaranteed to succeed for 256 bytes and fewer.

On Mac OS X, OpenBSD, and NetBSD genRandomNonBlocking is guaranteed to succeed for any number of bytes.

extern (C) @nogc nothrow @system
size_t
mir_random_genRandomNonBlocking
(
scope void* ptr
,
size_t len
)

Parameters

len size_t

length of the buffer (in bytes)

Return Value

Type: size_t

The number of bytes filled - a negative number if an error occurred

Examples

ubyte[] buf = new ubyte[10];
genRandomNonBlocking(buf);

int sum;
foreach (b; buf)
    sum += b;

assert(sum > 0, "Only zero points generated");

Meta