Golang math/rand.NewZipf() and Zipf.Uint64() functions example

package math/rand

Golang math/rand.NewZipf() and Zipf.Uint64() functions usage example

 package main

 import (
  "fmt"
  "math/rand"
  "time"
 )

 func main() {
  n := 10
  i := 0

  r := rand.New(rand.NewSource(time.Now().UnixNano()))
  zipf := rand.NewZipf(r, 3.14, 2.72, 5000)
  for i < n {
 fmt.Println(zipf.Uint64())
 i += 1
  }
 }

References :

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

http://golang.org/pkg/math/rand/#Zipf.Uint64

Advertisement