GetRandom functionv0.1.0
Fills up to length bytes of buffer with unpredictable bytes.
pub func GetRandom(
buffer: *var opaque,
length: uint,
flags: uint32
) -> int64
Returns the number of bytes actually written, or a negative error number. A request over 256 bytes may be cut
short, and a caller needing the whole buffer must call again for the rest.
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 rather than wait. Present for parity; FreeBSD's generator does not block.
RandomBlockingPool
pub const RandomBlockingPool: uint32 = 2;
GRND_RANDOM: accepted and ignored, which is what FreeBSD does with it.