2022-01-04 12:21:08 +03:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
2019-07-31 04:24:12 +03:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
module rand
|
|
|
|
|
2021-03-30 15:27:57 +03:00
|
|
|
struct ReadError {
|
2022-02-11 16:52:33 +03:00
|
|
|
Error
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (err ReadError) msg() string {
|
|
|
|
return 'crypto.rand.read() error reading random bytes'
|
2021-03-30 15:27:57 +03:00
|
|
|
}
|
2022-02-15 19:39:17 +03:00
|
|
|
|
|
|
|
// bytes returns an array of `bytes_needed` random bytes.
|
2022-03-06 20:01:22 +03:00
|
|
|
// Note: this call can block your program for a long period of time,
|
2022-02-15 19:39:17 +03:00
|
|
|
// if your system does not have access to enough entropy.
|
|
|
|
// See also rand.bytes(), if you do not need really random bytes,
|
|
|
|
// but instead pseudo random ones, from a pseudo random generator
|
|
|
|
// that can be seeded, and that is usually faster.
|
2022-10-20 22:14:33 +03:00
|
|
|
pub fn bytes(bytes_needed int) ![]u8 {
|
2022-02-15 19:39:17 +03:00
|
|
|
return read(bytes_needed)
|
|
|
|
}
|