Golang math/rand.ExpFloat64() function example

package math/rand

Golang math/rand.ExpFloat64() function usage example

 package main

 import (
 "fmt"
 "math/rand"
 )

 func main() {
 sum := 0.0
 n := 1000
 i := 0
 for i < n {
 x := rand.ExpFloat64()
 sum += x
 i += 1
 }

 expect := sum / (float64)(n)
 fmt.Println(expect)
 }

Reference :

http://golang.org/pkg/math/rand/#ExpFloat64

Advertisement