Skip to content

Instantly share code, notes, and snippets.

@paavohuhtala
Created October 29, 2017 08:45
Show Gist options
  • Save paavohuhtala/04cc6685192525248df851e571e47f91 to your computer and use it in GitHub Desktop.
Save paavohuhtala/04cc6685192525248df851e571e47f91 to your computer and use it in GitHub Desktop.
open System
open System.Collections.Generic
let samples = 100000
let rand = Random()
let lenTo1 () =
Seq.unfold (fun sum -> if sum > 1.0 then None else Some ((), sum + rand.NextDouble ())) 0.0
|> Seq.length
Seq.initInfinite (fun _ -> lenTo1 ())
|> Seq.take samples
|> Seq.map float
|> Seq.average
|> printfn "%f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment