github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/math/rand/v2/zipf.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // W.Hormann, G.Derflinger: 6 // "Rejection-Inversion to Generate Variates 7 // from Monotone Discrete Distributions" 8 // http://eeyore.wu-wien.ac.at/papers/96-04-04.wh-der.ps.gz 9 10 package rand 11 12 // Zipfは、Zipf分布に従う変量を生成します。 13 type Zipf struct { 14 r *Rand 15 imax float64 16 v float64 17 q float64 18 s float64 19 oneminusQ float64 20 oneminusQinv float64 21 hxm float64 22 hx0minusHxm float64 23 } 24 25 // NewZipfは、Zipf変量ジェネレータを返します。 26 // このジェネレータは、P(k)が(v + k) ** (-s)に比例するような値k ∈ [0, imax]を生成します。 27 // 要件:s > 1 および v >= 1。 28 func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf 29 30 // Uint64は、Zipfオブジェクトで記述されたZipf分布から抽出された値を返します。 31 func (z *Zipf) Uint64() uint64