How to Generate A Specific Number of Random Indices for Array Element Removal F#
问题 So sCount is the number of elements in the source array, iCount is the number of elements I want to remove. let indices = Array.init iCount (fun _ -> rng.Next sCount) |> Seq.distinct |> Seq.toArray |> Array.sort The problem with the method above is that I need to specifically remove iCount indices, and this doesn't guarantee that. I've tried stuff like while indices.Count < iCount do let x = rng.Next sCount if not (indices.Contains x) then indices <- indices.Add x And a few other similar