当前位置: 首页>>代码示例>>Golang>>正文


Golang rand.Float64函数代码示例

本文整理汇总了Golang中rand.Float64函数的典型用法代码示例。如果您正苦于以下问题:Golang Float64函数的具体用法?Golang Float64怎么用?Golang Float64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Float64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewSpoils

func NewSpoils(x, y float64) *Spoils {
	s := new(Spoils)
	if rand.Float64() > 0.2 {
		s.X, s.Y = -100, -100
		s.Dead = true
		return s
	}

	s.X = x
	s.Y = y
	s.Type = rand.Intn(2)

	s.Velocity = Vector64{(rand.Float64()*10 - 5) * 20, (rand.Float64()*10 - 5) * 20}

	switch s.Type {
	case SP_HEART:
		s.W = float64(IM.Misc[0].W)
		s.H = float64(IM.Misc[0].H)
	case SP_UPGRADE:
		s.W = 10
		s.H = 10
	}

	return s
}
开发者ID:zozor,项目名称:Cecils-Adventure,代码行数:25,代码来源:objects.go

示例2: renderPixel

func renderPixel(x int, y int, cx Vec, cy Vec) {
	var r1, r2 float64
	var dx, dy float64
	var radiance Vec
	var direction Vec

	for sy, i := 0, (h-y-1)*w+x; sy < 2; sy++ {
		for sx := 0; sx < 2; sx++ {
			radiance.x = 0
			radiance.y = 0
			radiance.z = 0
			for s := 0; s < samps; s++ {
				r1, r2 = 2*rand.Float64(), 2*rand.Float64()
				if r1 < 1 {
					dx = math.Sqrt(r1) - 1
				} else {
					dx = 1 - math.Sqrt(2-r1)
				}
				if r2 < 1 {
					dy = math.Sqrt(r2) - 1
				} else {
					dy = 1 - math.Sqrt(2-r2)
				}
				direction = Add(Add(SMul(cx, ((float64(sx)*.5+dx)/2+float64(x))/float64(w)-.5),
					SMul(cy, ((float64(sy)+.5+dy)/2+float64(y))/float64(h)-.5)), cam.Direction)
				radiance = Add(radiance, SMul(Radiance(&Ray{Add(cam.Origin, SMul(direction, 140.0)), Norm(direction)}, 0), 1.0/float64(samps)))
			}
			colors[i] = Add(colors[i], SMul(radiance, 0.25))
		}
	}
}
开发者ID:ggaughan,项目名称:smallpt.go,代码行数:31,代码来源:smallpt_parallel.go

示例3: Mutate

func (m *RandomMutator) Mutate(s *Subject) {
	for i := range s.Genome {
		v := rand.Float64()
		if v < m.prob {
			s.Genome[i] = rand.Float64()
		}
	}
	return
}
开发者ID:surma-dump,项目名称:genetics,代码行数:9,代码来源:mutator.go

示例4: GenerateRectangles

func GenerateRectangles(n int) []Rect {
	res := make([]Rect, n)
	for y := 0; y < n; y++ {
		res[y].h = rand.Float64()
		res[y].w = rand.Float64()
		res[y].x = rand.Float64()
		res[y].y = rand.Float64()
	}
	return res
}
开发者ID:mikhailt,项目名称:strip-packing,代码行数:10,代码来源:main.go

示例5: main

func main() {
	var t float64 = 0
	for i := 0; i < 100000000; i++ {
		t += rand.Float64()
	}
	fmt.Printf("total:%f\n", t)
}
开发者ID:kengonakajima,项目名称:simplegamebench,代码行数:7,代码来源:rand.go

示例6: seed

// use win-rate distribution of node to play a legal move in tracker
func (node *Node) seed(t Tracker, path []int) bool {
	if node.parent == nil {
		return false
	}
	dist := new(vector.Vector)
	sum := 0.0
	for sibling := node.parent.Child; sibling != nil; sibling = sibling.Sibling {
		for i := 0; i < len(path); i++ {
			if sibling.Vertex == path[i] {
				continue
			}
		}
		dist.Push(sibling.blendedMean)
		sum += sibling.blendedMean
	}
	node.totalseeds++
	r := rand.Float64() * sum
	for i := 0; i < dist.Len(); i++ {
		r -= dist.At(i).(float64)
		if r <= 0 {
			if t.Legal(node.Color, i) {
				t.Play(node.Color, i)
				node.seeds++
				return true
			}
			return false
		}
	}
	return false
}
开发者ID:etherealmachine,项目名称:hivemind,代码行数:31,代码来源:search.go

示例7: NewGenome

func (init *RandomInitializer) NewGenome(len int) (g Genome) {
	g = make(Genome, len)
	for i := range g {
		g[i] = rand.Float64()
	}
	return
}
开发者ID:surma-dump,项目名称:genetics,代码行数:7,代码来源:initializer.go

示例8: dither

func dither(d float64) int {
	dec := d - math.Floor(d)
	if rand.Float64() < dec {
		return int(math.Ceil(d))
	}
	return int(math.Floor(d))
}
开发者ID:mkb218,项目名称:mkfseq,代码行数:7,代码来源:syx.go

示例9: suggestion

func (t *HexTracker) suggestion(color byte, last int) int {
	if last == -1 || !t.config.PlayoutSuggest {
		return -1
	}
	var weights [6]float64
	weightSum := 0.0
	for i := range t.neighbors[1][last] {
		n := t.neighbors[1][last][i]
		if n != -1 && t.board[n] == EMPTY {
			if t.config.PlayoutSuggestUniform {
				weights[i] = 1
			} else {
				hash := hex_min_hash[hex_hash(color, t.board, t.neighbors[1][n])]
				hash |= 1 << 30
				weights[i] = t.config.policy_weights.Get(hash)
			}
			weightSum += weights[i]
		}
	}
	if weightSum > 0 {
		r := rand.Float64() * weightSum
		for i := range weights {
			if weights[i] > 0 {
				r -= weights[i]
				if r <= 0 {
					return t.neighbors[1][last][i]
				}
			}
		}
	}
	return -1
}
开发者ID:etherealmachine,项目名称:hivemind,代码行数:32,代码来源:hextracker.go

示例10: Randomize

func (g *GAFloatGenome) Randomize() {
	l := len(g.Gene)
	for i := 0; i < l; i++ {
		g.Gene[i] = rand.Float64()*g.Max + g.Min
	}
	g.Reset()
}
开发者ID:StepLg,项目名称:go-galib,代码行数:7,代码来源:genome_float64.go

示例11: ProcessTurns

func (self *Coordinator) ProcessTurns(complete chan bool) {
	for i := 0; i < 3; /* <3 <3 <3 */ i++ { // TODO: THREE TIMES IS ARBITRARY AND FOR TESTING

		self.log.Printf("Making turn %d available", i)
		for pi, _ := range self.peers {
			self.nextTurnAvailableSignals[pi] <- i
		}

		responses := self.peerDataForTurn(i)
		_ = self.transformsForNextTurn(responses)

		if self.conf.RandomlyDelayProcessing {
			time.Sleep(int64(float64(1e9) * rand.Float64()))
		}

		// Wait for all RPC requests from peers to go through the other goroutine
		for _, _ = range self.peers {
			<-self.rpcRequestsReceivedConfirmation
		}

		self.availableGameState.Advance()
		//  i, agent
		for _, _ = range self.availableGameState.Agents {
			// agent.Apply(transforms[i])
		}
	}

	self.log.Printf("Sending complete")

	if complete != nil {
		complete <- true
	}
}
开发者ID:andradeandrey,项目名称:Tecellate,代码行数:33,代码来源:processingloop.go

示例12: SendChats

func (c *Chatter) SendChats() {
	for {
		duration := -1 * math.Log(rand.Float64()) * c.average * 1e9
		time.Sleep(int64(duration))
		c.Messages <- c.mark.Generate()
	}
}
开发者ID:zeebo,项目名称:chatters,代码行数:7,代码来源:chatters.go

示例13: GenIndividual

func GenIndividual() Individual {
	var i Individual
	i.bets[0] = (rand.Float64() * money)
	if i.bets[0] < MINBET {
		i.bets[0] = 0
	}
	i.bets[1] = (rand.Float64() * (money - i.bets[0]))
	if i.bets[1] < MINBET {
		i.bets[1] = 0
	}
	i.bets[2] = rand.Float64() * (money - (i.bets[0] + i.bets[1]))
	if i.bets[2] < MINBET {
		i.bets[2] = 0
	}
	return i
}
开发者ID:aquilax,项目名称:go-genetic-bet,代码行数:16,代码来源:bet.go

示例14: PickWanderForAnt

func PickWanderForAnt(state *State, ant *Ant) []*Square {
	valid := ant.square.Neighbors().Minus(ant.square.Blacklist())
	if len(valid) == 0 {
		return make(Route, 0)
	}

	var randomSquare *Square = nil
	maxScore := -1.0
	for _, neighbor := range valid {
		// better to wander to a square that's well-connected
		neighborValid := neighbor.Neighbors().Minus(neighbor.Blacklist())
		score := rand.Float64() * (float64)(len(neighborValid))

		// best to wander to a square we've never visited
		if !neighbor.visited {
			score += 3.0
		}

		if score > maxScore {
			maxScore = score
			randomSquare = neighbor
		}
	}

	route := make(Route, 1)
	route[0] = randomSquare
	return route
}
开发者ID:bradleybuda,项目名称:ants,代码行数:28,代码来源:goal.go

示例15: GenPatternRule

func GenPatternRule(alpha string, min int, max int) *PatternRule {
	leftSide := RandomString(alpha, min, max)
	rightSide := RandomString(alpha, min, max)
	cost := rand.Float64() * 10

	return &PatternRule{leftSide, rightSide, cost}
}
开发者ID:rahcola,项目名称:str-project,代码行数:7,代码来源:utils.go


注:本文中的rand.Float64函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。