| ... | ... | @@ -3,21 +3,22 @@ |
| 3 | 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. |
| 4 | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | 5 | // and substantial portions of the software. |
| 6 | | // The engines provided here should be initialized from an external source. For now, randomBytes |
| 7 | | // from the crypto package is the most suitable. Be sure to use a CSPRNG when required, otherwise using |
| 8 | | // a normal PRNG will be faster and use substantially less stack space. |
| 9 | | // |
| 10 | | // ``` |
| 11 | | // var buf: [8]u8 = undefined; |
| 12 | | // try std.crypto.randomBytes(buf[0..]); |
| 13 | | // const seed = mem.readIntLittle(u64, buf[0..8]); |
| 14 | | // |
| 15 | | // var r = DefaultPrng.init(seed); |
| 16 | | // |
| 17 | | // const s = r.random.int(u64); |
| 18 | | // ``` |
| 19 | | // |
| 20 | | // TODO(tiehuis): Benchmark these against other reference implementations. |
| 6 | |
| 7 | //! The engines provided here should be initialized from an external source. For now, randomBytes |
| 8 | //! from the crypto package is the most suitable. Be sure to use a CSPRNG when required, otherwise using |
| 9 | //! a normal PRNG will be faster and use substantially less stack space. |
| 10 | //! |
| 11 | //! ``` |
| 12 | //! var buf: [8]u8 = undefined; |
| 13 | //! try std.crypto.randomBytes(buf[0..]); |
| 14 | //! const seed = mem.readIntLittle(u64, buf[0..8]); |
| 15 | //! |
| 16 | //! var r = DefaultPrng.init(seed); |
| 17 | //! |
| 18 | //! const s = r.random.int(u64); |
| 19 | //! ``` |
| 20 | //! |
| 21 | //! TODO(tiehuis): Benchmark these against other reference implementations. |
| 21 | 22 | |
| 22 | 23 | const std = @import("std.zig"); |
| 23 | 24 | const builtin = @import("builtin"); |
| ... | ... | @@ -29,10 +30,10 @@ const math = std.math; |
| 29 | 30 | const ziggurat = @import("rand/ziggurat.zig"); |
| 30 | 31 | const maxInt = std.math.maxInt; |
| 31 | 32 | |
| 32 | | // When you need fast unbiased random numbers |
| 33 | /// Fast unbiased random numbers. |
| 33 | 34 | pub const DefaultPrng = Xoroshiro128; |
| 34 | 35 | |
| 35 | | // When you need cryptographically secure random numbers |
| 36 | /// Cryptographically secure random numbers. |
| 36 | 37 | pub const DefaultCsprng = Isaac64; |
| 37 | 38 | |
| 38 | 39 | pub const Random = struct { |