當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Rand.Float64方法代碼示例

本文整理匯總了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
		}
	}
}
開發者ID:fedgrant,項目名稱:tonika,代碼行數:11,代碼來源:fork.go

示例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
			}
		}
	}

}
開發者ID:mirzathegr8,項目名稱:GoSynstation,代碼行數:52,代碼來源:physReceiver.go

示例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
}
開發者ID:go-nosql,項目名稱:golang,代碼行數:8,代碼來源:quick.go

示例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)
}
開發者ID:go-nosql,項目名稱:golang,代碼行數:8,代碼來源:quick.go

示例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
}
開發者ID:nathanbeckmann,項目名稱:Tournament,代碼行數:5,代碼來源:player.go

示例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
	}
}
開發者ID:nictuku,項目名稱:chunkymonkey,代碼行數:7,代碼來源:perlin.go

示例7: getCoord

func getCoord(rg *rand.Rand) float64 {
	return -1 + rg.Float64()
}
開發者ID:remogatto,項目名稱:go-benchmarks,代碼行數:3,代碼來源:pi.go


注:本文中的rand.Rand.Float64方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。