| author | |
| committer | |
| log | e6be6d97683d5443f48ce8b6d86fdf27f0f1d556 |
| tree | 7348ad6c9a7816dd618c7053e1addc7bf27c717d |
| parent | 527055a8215b23a13fb407bdeba2908b8206f6f0 |
The function does not mutate the proportions and the signature should reflect that.2 files changed, 2 insertions(+), 2 deletions(-)
lib/std/rand.zig+1-1| ... | ... | @@ -343,7 +343,7 @@ pub const Random = struct { |
| 343 | 343 | /// |
| 344 | 344 | /// This is useful for selecting an item from a slice where weights are not equal. |
| 345 | 345 | /// `T` must be a numeric type capable of holding the sum of `proportions`. |
| 346 | pub fn weightedIndex(r: std.rand.Random, comptime T: type, proportions: []T) usize { | |
| 346 | pub fn weightedIndex(r: std.rand.Random, comptime T: type, proportions: []const T) usize { | |
| 347 | 347 | // This implementation works by summing the proportions and picking a random |
| 348 | 348 | // point in [0, sum). We then loop over the proportions, accumulating |
| 349 | 349 | // until our accumulator is greater than the random point. |
lib/std/rand/test.zig+1-1| ... | ... | @@ -452,7 +452,7 @@ test "Random weightedIndex" { |
| 452 | 452 | var prng = DefaultPrng.init(0); |
| 453 | 453 | const random = prng.random(); |
| 454 | 454 | |
| 455 | var proportions = [_]T{ 2, 1, 1, 2 }; | |
| 455 | const proportions = [_]T{ 2, 1, 1, 2 }; | |
| 456 | 456 | var counts = [_]f64{ 0, 0, 0, 0 }; |
| 457 | 457 | |
| 458 | 458 | const n_trials: u64 = 10_000; |