GetRandom functionv0.1.0
pub func GetRandom(
buffer: *var opaque,
length: uint,
flags: uint32
) -> int64
buffer is borrowed and written; length and flags are read by value. Returns the number of bytes actually
written, or a negative error number.
A short count is ordinary rather than a failure: a request over 256 bytes can be cut short by a signal, and a
caller needing the whole buffer must call again for the rest. Without RandomNonBlocking the first call in the
life of a system may wait for the pool to be seeded; after that it does not wait at all.
Runs in time proportional to length and allocates nothing.
buffer must be writable for length bytes. Treat a short count as bytes obtained, not as failure, or the
unwritten tail stays whatever it held — which for a key is the worst possible outcome.
Parameters
| Name | Type | Description |
|---|---|---|
buffer | *var opaque | receives the bytes |
length | uint | how many bytes to ask for |
flags | uint32 | zero, or one of the Random* values |
Returns: the bytes written, which may be fewer than asked for, or a negative error number
Related
RandomNonBlocking
pub const RandomNonBlocking: uint32 = 1;
GRND_NONBLOCK: report EAGAIN rather than waiting for the pool to be seeded.
RandomBlockingPool
pub const RandomBlockingPool: uint32 = 2;
GRND_RANDOM: draw from the blocking pool, which is almost never what a caller wants.
Kept for completeness. The default source is as unpredictable and does not stall.