I have piece of code that should generate 10000 4-size arrays whose sum is 100000. but once it generates the first array the others are the same. And I have no idea why.
let mutable sum = 0 let mutable temp = 0
let test: int [] [] = Array.init 10000 (fun _ ->
sum <- 0
temp <- 0
let test = Array.init 4 (fun i ->
if not (i = 4) then
let y = System.Random()
temp <- y.Next((100000 - sum) / (4 - i)) + 1
sum <- sum + temp
temp
else
let mutable k = 100000 - sum
sum <- sum + temp
k)
test)
Aucun commentaire:
Enregistrer un commentaire