Example #1
0
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
		}
	}
}
Example #2
0
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
			}
		}
	}

}
Example #3
0
// 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
}
Example #4
0
// 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)
}
Example #5
0
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
}
Example #6
0
// 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
	}
}
Example #7
0
func getCoord(rg *rand.Rand) float64 {
	return -1 + rg.Float64()
}