Function RtlGenRandom [src]
Call RtlGenRandom() instead of CryptGetRandom() on Windows
https://github.com/rust-lang-nursery/rand/issues/111
https://bugzilla.mozilla.org/show_bug.cgi?id=504270
Prototype
pub fn RtlGenRandom(output: []u8) RtlGenRandomError!void Parameters
output: []u8 Possible Errors
RtlGenRandom has been known to fail in situations where the system is under heavy load.
Unfortunately, it does not call SetLastError, so it is not possible to get more specific
error information; it could actually be due to an out-of-memory condition, for example.
Source
pub fn RtlGenRandom(output: []u8) RtlGenRandomError!void {
var total_read: usize = 0;
var buff: []u8 = output[0..];
const max_read_size: ULONG = maxInt(ULONG);
while (total_read < output.len) {
const to_read: ULONG = @min(buff.len, max_read_size);
if (advapi32.RtlGenRandom(buff.ptr, to_read) == 0) {
return error.SystemResources;
}
total_read += to_read;
buff = buff[to_read..];
}
}