The OpenD Programming Language

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.

  1. alias genRandomNonBlocking = mir_random_genRandomNonBlocking
    import mir.random.engine;
    alias genRandomNonBlocking = mir_random_genRandomNonBlocking
  2. size_t genRandomNonBlocking(ubyte[] buffer)

Return Value

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