A função de chamada F # que retorna o registro para loop for executado apenas uma vez
Eu trabalho principalmente em C # e sou novo nas linguagens de funções F # / e estou tendo um problema com um programa bastante simples. Eu tenho uma função que cria um registro com dois campos inteiros. Os campos são escolhidosSystem.Random.NextDouble
dentro de ummatch
para alinhar com certas probabilidades. Em seguida, tenho um loop for que deve executar ocreateCustomer
função quatro vezes.
O problema que estou tendo é que oCustomer
é o mesmo para todas as 10 iterações do loop for e doprintfn
dentro degetIATime
apenas parece ser executado uma vez.
Program.fs
open Simulation
[<EntryPoint>]
let main argv =
printfn "%A" argv
printfn "Test"
for i in 1 .. 10 do
let mutable customer = createCustomer
printfn "i: %d\tIA: %d\tService: %d" i customer.interArrivalTime customer.serviceTime
ignore (System.Console.ReadLine()) //Wait for keypress @ the end
0 // return an integer exit code
Simulation.fs
module Simulation
type Customer = {
interArrivalTime: int
serviceTime: int
}
let createCustomer =
let getRand =
let random = new System.Random()
fun () -> random.NextDouble()
let getIATime rand =
printf "Random was: %f\n" rand
match rand with
| rand when rand <= 0.09 -> 0
| rand when rand <= 0.26 -> 1
| rand when rand <= 0.53 -> 2
| rand when rand <= 0.73 -> 3
| rand when rand <= 0.88 -> 4
| rand when rand <= 1.0 -> 5
let getServiceTime rand =
match rand with
| rand when rand <= 0.2 -> 1
| rand when rand <= 0.6 -> 2
| rand when rand <= 0.88 -> 3
| rand when rand <= 1.0 -> 4
{interArrivalTime = getIATime (getRand()); serviceTime = getServiceTime (getRand())}