Commit multiple function scores to F #

I am trying to create a random number generator in F #.

I have successfully created the following function:

let draw () =
    let rand = new Random()
    rand.Next(0,36)

This works fine and generates a number from 0 to 36.

However, I am trying to create a function that runs this function several times.

I tried the following

let multipleDraws (n:int) =
    [for i in 1..n -> draw()]

However, I get only one result, as it drawis evaluated only once in understanding.

How can I force multiple function executions draw?

+5
source share
2 answers

. , . , , .

:

let draw =
    let rand = new Random()
    fun () ->
    rand.Next(0,36)

:

let multipleDraws (n:int) =
    [for i in 1..n -> draw()]
+8

, .

-.

let draw =
    let rand = new Random()
    fun () ->
    rand.Next(0,36)

, , - .

let draw =
    let rand = new Random()
    let next() =
        rand.Next(0,36)
    next

. rand , .

let rand = new Random()
let next() =
    rand.Next(0,36)
let draw = next

, Ramon , SRKX.

Ramon Random, , . , . , new Random(2). , . , new Random , , , ( ). , . SRKX multipleDraws , , , .

+6

All Articles