La función de llamada F # que devuelve el registro for loop solo se ejecuta una vez
Principalmente trabajo en C # y soy nuevo en F # / lenguajes de funciones y tengo un problema con un programa bastante simple. Tengo una función que crea un registro con dos campos enteros. Los campos son elegidosSystem.Random.NextDouble
dentro de unamatch
para alinearse con ciertas probabilidades. Entonces tengo un bucle for que debería ejecutar elcreateCustomer
funcionan cuatro veces.
El problema que tengo es que elCustomer
es lo mismo para las 10 iteraciones del bucle for y elprintfn
dentro degetIATime
solo parece ejecutarse una 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())}