Random generation to fsharp's list

I am trying to use F # to create a list of random triples -> two random numbers and their sum:

let foo minNum maxNum = 
    let rnd = System.Random()
    let first = rnd.Next(minNum, maxNum)
    let second = rnd.Next(minNum, maxNum)
    let third = first + second
    first, second, third

which can be called that and works well (always gives a new random number) (when using F # interactive)

foo 0 50

When trying to generate a list of random triples like this

List.init 100 (fun index -> foo 0 50)

I would like it to be a list of 100 randomized triples , but instead they all have the same meaning. I see that the function is independent of the index and therefore does not need to be recalculated, but I'm not sure how to get around it (I tried to enter the index as an unused dummy variable, also tried to present the index as a random seed, but it didn’t help)

+5
source share
3

, , , , , - , foo 0 50 . . , , ( ). , , .

, foo 0 50 - 100 , . , 100 , .

, ?

Random , foo. , . , , . , 100 , , 100 .

, , foo.

+14

. , :

let foo  = 
    let rnd = System.Random()
    fun  minNum maxNum ->
        let first = rnd.Next(minNum, maxNum)
        let second = rnd.Next(minNum, maxNum)
        let third = first + second
        first, second, third

, Next , , foo , Next.

+11

To complement sepp2k with an answer using some code:

let rnd = System.Random()

let foo minNum maxNum = 
    let first = rnd.Next(minNum, maxNum)
    let second = rnd.Next(minNum, maxNum)
    let third = first + second
    first, second, third
+3
source

All Articles