| ... | ... | @@ -30,7 +30,7 @@ pub const DefaultCsprng = Isaac64; |
| 30 | 30 | pub const Random = struct { |
| 31 | 31 | fillFn: fn (r: *Random, buf: []u8) void, |
| 32 | 32 | |
| 33 | | /// Read random bytes into the specified buffer until fill. |
| 33 | /// Read random bytes into the specified buffer until full. |
| 34 | 34 | pub fn bytes(r: *Random, buf: []u8) void { |
| 35 | 35 | r.fillFn(r, buf); |
| 36 | 36 | } |
| ... | ... | @@ -48,10 +48,10 @@ pub const Random = struct { |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | | /// Get a random unsigned integer with even distribution between `start` |
| 52 | | /// inclusive and `end` exclusive. |
| 51 | /// Return a random integer with even distribution between `start` |
| 52 | /// inclusive and `end` exclusive. `start` must be less than `end`. |
| 53 | 53 | pub fn range(r: *Random, comptime T: type, start: T, end: T) T { |
| 54 | | assert(start <= end); |
| 54 | assert(start < end); |
| 55 | 55 | if (T.is_signed) { |
| 56 | 56 | const uint = @IntType(false, T.bit_count); |
| 57 | 57 | if (start >= 0 and end >= 0) { |
| ... | ... | @@ -664,6 +664,7 @@ test "Random range" { |
| 664 | 664 | testRange(&prng.random, -4, 3); |
| 665 | 665 | testRange(&prng.random, -4, -1); |
| 666 | 666 | testRange(&prng.random, 10, 14); |
| 667 | // TODO: test that prng.random.range(1, 1) causes an assertion error |
| 667 | 668 | } |
| 668 | 669 | |
| 669 | 670 | fn testRange(r: *Random, start: i32, end: i32) void { |