Landin library reference discuss source

hosted/system/entropy.ldn

1--  The hosted provider's `io.entropy`: the system's random bytes, fit for
2--  keys, through platform/posix.  Written once, like the rest.
3
4import core/io
5import platform/posix
6
7--  The system gives at most so much at once, and a signal may interrupt it
8--  before it gives anything; both are asked again for the rest.
9system_fill_random: (self: host, into: []mut u8) -> none ! io.io_failed =
10    self.failure.val = 0
11    mut filled: usize = 0
12    while filled < lenof into do
13        got: usize = posix.random_bytes(into[filled..<lenof into]) else (problem)
14            continue when problem == posix.eintr
15            record(self, problem)
16            fail io.io_failed
17        end
18        fail io.io_failed when got == 0 or got > lenof into - filled
19        filled += got
20    end while
21end system_fill_random
22
23host is io.entropy (fill_random: system_fill_random)