1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

rand: add pub fn rand.read(mut buf []byte) and pub fn rand.bytes(needed int) ?[]byte{} + tests

This commit is contained in:
Delyan Angelov
2022-02-06 10:49:43 +02:00
parent ece73836aa
commit 66f21cae55
4 changed files with 82 additions and 0 deletions

View File

@ -65,3 +65,10 @@ pub fn ulid_at_millisecond(unix_time_milli u64) string {
return res
}
// read fills in `buf` a maximum of `buf.len` random bytes
pub fn read(mut buf []byte) {
for i in 0 .. buf.len {
buf[i] = byte(default_rng.u32())
}
}