mardi 18 novembre 2014

Generate two different randoms in F#


Vote count:

0




I have a F# list and I'm taking two elements of that list.

If the list has 10 elements in it :



let rnd = new Random()
let elem1 = list.Item(rnd.Next(0,9))
let elem2 = list.Item(rnd.Next(0,9))


There is a chance elem1 and elem2 are equal.

I have checked some workarounds and most of them work using a do while, but I don't want to implement a function that may never end in F#.

Is there a way to create a restriction in the random function?



First random : 0 <= x <= 9
Second random : 0 <= y <= 9 <> x


asked 1 min ago







Generate two different randoms in F#

Aucun commentaire:

Enregistrer un commentaire