Source File
zipf.go
Belonging Package
golang.org/x/exp/rand
package rand
import
type Zipf struct {
r *Rand
imax float64
v float64
q float64
s float64
oneminusQ float64
oneminusQinv float64
hxm float64
hx0minusHxm float64
}
func ( *Zipf) ( float64) float64 {
return math.Exp(.oneminusQ*math.Log(.v+)) * .oneminusQinv
}
func ( *Zipf) ( float64) float64 {
return math.Exp(.oneminusQinv*math.Log(.oneminusQ*)) - .v
}
func ( *Rand, float64, float64, uint64) *Zipf {
:= new(Zipf)
if <= 1.0 || < 1 {
return nil
}
.r =
.imax = float64()
.v =
.q =
.oneminusQ = 1.0 - .q
.oneminusQinv = 1.0 / .oneminusQ
.hxm = .h(.imax + 0.5)
.hx0minusHxm = .h(0.5) - math.Exp(math.Log(.v)*(-.q)) - .hxm
.s = 1 - .hinv(.h(1.5)-math.Exp(-.q*math.Log(.v+1.0)))
return
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |