本文整理汇总了Golang中rand.Rand.Float64方法的典型用法代码示例。如果您正苦于以下问题:Golang Rand.Float64方法的具体用法?Golang Rand.Float64怎么用?Golang Rand.Float64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rand.Rand
的用法示例。
在下文中一共展示了Rand.Float64方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: choose
func choose(fork forkChoice, random *rand.Rand) {
pivot := random.Float64() * fork.TotalMass()
fork.Reset()
for prob, _, ok := fork.Next(); ok; prob, _, ok = fork.Next() {
pivot -= prob
if pivot <= 0.0 {
fork.Pick()
return
}
}
}
示例2: Init
func (s *shadowMap) Init(corr_dist float64, Rgen2 *rand.Rand) {
nval := int(Field / corr_dist / shadow_sampling)
//fmt.Println(" shadowMap down Sampling ", shadow_sampling, " ", nval)
s.xcos = make([]float64, nval)
s.ycos = make([]float64, nval)
s.xsin = make([]float64, nval)
s.ysin = make([]float64, nval)
for i := 0; i < nval; i++ {
s.xcos[i] = Rgen2.NormFloat64()
//s.xcos[i] *= s.xcos[i]
s.ycos[i] = Rgen2.NormFloat64()
s.xsin[i] = Rgen2.Float64() * 2 * math.Pi
s.ysin[i] = Rgen2.Float64() * 2 * math.Pi
if s.xcos[i] < mval {
s.xcos[i] = 0
}
if s.ycos[i] < mval {
s.ycos[i] = 0
}
s.power += s.xcos[i] * s.xcos[i]
s.power += s.ycos[i] * s.ycos[i]
}
s.power = math.Sqrt(s.power) / shadow_deviance
for i := 0; i < nval; i++ {
s.xcos[i] /= s.power
s.ycos[i] /= s.power
}
s.smap = make([][]float32, mapsize)
for i := 0; i < mapsize; i++ {
s.smap[i] = make([]float32, mapsize)
x := (float64(i) - mapsize/2) / mapres
for j := 0; j < mapsize; j++ {
d := geom.Pos{x, (float64(j) - mapsize/2) / mapres}
s.smap[i][j] = float32(s.evalShadowFadingDirect(d))
//lets not have -Inf here
if s.smap[i][j] < 0.0000001 {
s.smap[i][j] = 0.0000001
}
}
}
}
示例3: randFloat64
// randFloat64 generates a random float taking the full range of a float64.
func randFloat64(rand *rand.Rand) float64 {
f := rand.Float64()
if rand.Int()&1 == 1 {
f = -f
}
return f
}
示例4: randFloat32
// randFloat32 generates a random float taking the full range of a float32.
func randFloat32(rand *rand.Rand) float32 {
f := rand.Float64() * math.MaxFloat32
if rand.Int()&1 == 1 {
f = -f
}
return float32(f)
}
示例5: performance
func (p Player) performance(r *rand.Rand) float64 {
dev := (r.Float64()*2.0 - 1.0)
dev = math.Fabs(dev) * dev * p.dev
return p.mean + dev
}
示例6: randVector
// randVector generates a random vector whose components are each in the range
// [-1, 1). The dimensionality of the vector is len(c).
func randVector(c []float64, rnd *rand.Rand) {
for i := range c {
c[i] = 2*rnd.Float64() - 1
}
}
示例7: getCoord
func getCoord(rg *rand.Rand) float64 {
return -1 + rg.Float64()
}