diff --git a/lib/std/rand.zig b/lib/std/rand.zig index c13d2895c9fc2508c06ba26fa4ebd1840bd553bb..e94578c1196fb1b11524119038fac9e2ba5d4f55 100644 --- a/lib/std/rand.zig +++ b/lib/std/rand.zig @@ -343,7 +343,7 @@ pub const Random = struct { /// /// This is useful for selecting an item from a slice where weights are not equal. /// `T` must be a numeric type capable of holding the sum of `proportions`. - pub fn weightedIndex(r: std.rand.Random, comptime T: type, proportions: []T) usize { + pub fn weightedIndex(r: std.rand.Random, comptime T: type, proportions: []const T) usize { // This implementation works by summing the proportions and picking a random // point in [0, sum). We then loop over the proportions, accumulating // until our accumulator is greater than the random point. diff --git a/lib/std/rand/test.zig b/lib/std/rand/test.zig index cae77d6e37eeb309336601a69db1a9e463257dc5..1ad9adbeb80c275f909eb375a113272850a2a150 100644 --- a/lib/std/rand/test.zig +++ b/lib/std/rand/test.zig @@ -452,7 +452,7 @@ test "Random weightedIndex" { var prng = DefaultPrng.init(0); const random = prng.random(); - var proportions = [_]T{ 2, 1, 1, 2 }; + const proportions = [_]T{ 2, 1, 1, 2 }; var counts = [_]f64{ 0, 0, 0, 0 }; const n_trials: u64 = 10_000;