| 1 | // Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | |
| 5 | module rand |
| 6 | |
| 7 | struct ReadError { |
| 8 | Error |
| 9 | } |
| 10 | |
| 11 | // msg returns the error message. |
| 12 | pub fn (err ReadError) msg() string { |
| 13 | return 'crypto.rand.read() error reading random bytes' |
| 14 | } |
| 15 | |
| 16 | // bytes returns an array of `bytes_needed` random bytes. |
| 17 | // Note: this call can block your program for a long period of time, |
| 18 | // if your system does not have access to enough entropy. |
| 19 | // See also rand.bytes(), if you do not need really random bytes, |
| 20 | // but instead pseudo random ones, from a pseudo random generator |
| 21 | // that can be seeded, and that is usually faster. |
| 22 | pub fn bytes(bytes_needed int) ![]u8 { |
| 23 | return read(bytes_needed) |
| 24 | } |
| 25 | |