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


Golang rand.ExpFloat64函數代碼示例

本文整理匯總了Golang中math/rand.ExpFloat64函數的典型用法代碼示例。如果您正苦於以下問題:Golang ExpFloat64函數的具體用法?Golang ExpFloat64怎麽用?Golang ExpFloat64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ExpFloat64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: makeFlows

func (fg FlowGenerator) makeFlows(logger chan LogEvent) EventQueue {
	lambda := (fg.bandwidth * 1e9 * fg.load) / (fg.cdf.meanFlowSize() * 1500 * 8)
	lambda /= 143

	creationQueue := make(EventQueue, 0)
	defer func() {
		creationQueue = nil
	}()

	heap.Init(&creationQueue)
	for i := 0; i < NUM_HOSTS; i++ {
		for j := 0; j < NUM_HOSTS; j++ {
			if i == j {
				continue
			}
			f := &Flow{Start: 1e6 + (rand.ExpFloat64()/lambda)*1e6, Size: fg.cdf.value(), Source: uint8(i), Dest: uint8(j), LastTime: 0, FinishEvent: nil}
			heap.Push(&creationQueue, makeCreationEvent(f))
		}
	}

	eventQueue := make(EventQueue, 0)
	for uint(len(eventQueue)) < fg.numFlows {
		ev := heap.Pop(&creationQueue).(*Event)
		logger <- LogEvent{Time: 0, Type: LOG_FLOW_GEN, Flow: ev.Flow}
		eventQueue = append(eventQueue, makeArrivalEvent(ev.Flow))

		nextTime := ev.Time + (rand.ExpFloat64()/lambda)*1e6
		f := &Flow{Start: nextTime, Size: fg.cdf.value(), Source: ev.Flow.Source, Dest: ev.Flow.Dest, LastTime: 0, FinishEvent: nil}
		heap.Push(&creationQueue, makeCreationEvent(f))
	}

	return eventQueue
}
開發者ID:NetSys,項目名稱:ideal-simulator,代碼行數:33,代碼來源:flowgen.go

示例2: BenchmarkReadFloat

func BenchmarkReadFloat(b *testing.B) {
	b.StopTimer()
	c := new(Context)

	rand.Seed(time.Now().UnixNano())
	max := 512
	floats := make([]*bytes.Buffer, max)

	for i := 0; i < max; i++ {
		w := new(bytes.Buffer)
		v := rand.ExpFloat64() - rand.ExpFloat64()
		w.Write([]byte{ettNewFloat})
		binary.Write(w, binary.BigEndian, math.Float64bits(v))
		floats[i] = w
	}

	b.StartTimer()

	for i := 0; i < b.N; i++ {
		in := floats[i%max]
		_, err := c.Read(in)

		if err != io.EOF && err != nil {
			b.Fatal(err)
		}
	}
}
開發者ID:agelin,項目名稱:etf,代碼行數:27,代碼來源:read_b_test.go

示例3: s

func s(numTrains int, safetyTime int, rideTime int, minTransTime int, avgTransTime int) []int {
	d := make([]int, 0)

	trains := make([]int, numTrains)
	c := 0
	avg := float64(avgTransTime - minTransTime)
	t := 0
	dep := minTransTime + int(rand.ExpFloat64()*avg)
	t = dep
	trains[c] = dep + rideTime
	c = (c + 1) % numTrains
	d = append(d, dep)
	for t < 43200 { //in seconds
		if trains[c] > t {
			t = trains[c]
		}
		t += minTransTime + int(rand.ExpFloat64()*avg)
		if t < dep+safetyTime {
			t = dep + safetyTime
		}
		dep = t
		d = append(d, dep)
	}
	fmt.Println(d)
	return d
}
開發者ID:Smedira,項目名稱:GO-Amusement,代碼行數:26,代碼來源:sim.go

示例4: TestCompressionRatio

func TestCompressionRatio(t *testing.T) {
	r := rand.New(rand.NewSource(0))
	mean := 0.0
	count := 100
	for i := 0; i < count; i++ {
		length := r.Intn(5000) + 100
		c := NewCompressionBuffer()
		data := []float64{}
		value := rand.ExpFloat64() * 1e-5
		for j := 0; j < length; j++ {
			if rand.Intn(10) != 0 {
				value += rand.ExpFloat64()
			}
			data = append(data, value)
		}
		c.Compress(data)
		c.Finalize()
		compressed := c.Bytes()
		compressionRatio := float64(length*8) / float64(len(compressed))
		if compressionRatio < 1 {
			t.Errorf("Data size was increased when compressed")
			t.Errorf("Compression ratio: %f; original %d: compressed %d", float64(length*8)/float64(len(compressed)), length*8, len(compressed))
		}
		mean += compressionRatio
	}
	mean = mean / float64(count)
	t.Logf("mean compression ratio: %f", mean)
}
開發者ID:deveshmittal,項目名稱:metrics,代碼行數:28,代碼來源:compress_test.go

示例5: singleServer

func singleServer() {
	for i := 0; i < 1000; i++ {
		fmt.Println("NormFloat64", rand.NormFloat64(),
			"Int63n", rand.Int63n(100),
			"ExpFloat64", rand.ExpFloat64())
	}
}
開發者ID:taysom,項目名稱:va,代碼行數:7,代碼來源:main.go

示例6: Evolve

// Evolve implements the inner loop of the evolutionary algorithm.
// The population calls the Evolve method of each genome, in parallel. Then,
// each receiver returns a value to replace it in the next generation.
func (q *queens) Evolve(matingPool ...evo.Genome) evo.Genome {
	// Crossover:
	// We're implementing a diffusion model. For each member of the population,
	// we receive a small mating pool containing only our neighbors. We choose
	// a mate using a random binary tournament and create a child with
	// partially mapped crossover.
	mate := sel.BinaryTournament(matingPool...).(*queens)
	child := &queens{gene: pool.Get().([]int)}
	perm.PMX(child.gene, q.gene, mate.gene)

	// Mutation:
	// Perform n random swaps where n is taken from an exponential distribution.
	mutationCount := math.Ceil(rand.ExpFloat64() - 0.5)
	for i := float64(0); i < mutationCount; i++ {
		j := rand.Intn(len(child.gene))
		k := rand.Intn(len(child.gene))
		child.gene[j], child.gene[k] = child.gene[k], child.gene[j]
	}

	// Replacement:
	// Only replace if the child is better or equal.
	if q.Fitness() > child.Fitness() {
		return q
	}
	return child
}
開發者ID:lucmichalski,項目名稱:evo,代碼行數:29,代碼來源:queens_test.go

示例7: randomSlice

func randomSlice(n int) []float64 {
	slice := make([]float64, n)
	for i := range slice {
		slice[i] = rand.ExpFloat64()
	}
	return slice
}
開發者ID:deveshmittal,項目名稱:metrics,代碼行數:7,代碼來源:forecast_test.go

示例8: gaussianNoise

func gaussianNoise(data []float64) []float64 {
	result := make([]float64, len(data))
	for i := range data {
		result[i] = data[i] + rand.ExpFloat64()
	}
	return result
}
開發者ID:deveshmittal,項目名稱:metrics,代碼行數:7,代碼來源:rolling_test.go

示例9: main

func main() {
	end = make(map[int64]int)
	b := big.NewInt(int64(10))
	for i := 0; i < size; i++ {
		r, _ := c_rand.Int(c_rand.Reader, b)
		m := r.Int64()
		end[m]++
	}

	for i, j := range end {
		fmt.Print(i)
		for m := 0; m < j/(size/100); m++ {
			fmt.Print("*")
		}
		fmt.Println("	", j)
	}

	for i := 0; i < 11; i++ {
		fmt.Println(c_rand.Prime(c_rand.Reader, 64))
	}

	for i := 0; i < 11; i++ {
		fmt.Println(m_rand.ExpFloat64())
	}
}
開發者ID:cchd0001,項目名稱:gld_work,代碼行數:25,代碼來源:test.go

示例10: sendMulti

// Generate and send a random GetValuesSingle request.
func (l *Load) sendMulti(client *gen.HFileServiceClient, diff *gen.HFileServiceClient) {
	numKeys := int(math.Abs(rand.ExpFloat64()*10) + 1)
	keys := l.randomKeys(numKeys)
	r := &gen.SingleHFileKeyRequest{HfileName: &l.collection, SortedKeys: keys}

	before := time.Now()
	resp, err := client.GetValuesMulti(r)
	if err != nil {
		log.Println("[GetValuesMulti] Error fetching value:", err, util.PrettyKeys(keys))
	}
	report.TimeSince(l.rtt+".overall", before)
	report.TimeSince(l.rtt+".getValuesMulti", before)

	if diff != nil {
		beforeDiff := time.Now()
		diffResp, diffErr := diff.GetValuesMulti(r)
		if diffErr != nil {
			log.Println("[GetValuesMulti] Error fetching diff value:", diffErr, util.PrettyKeys(keys))
		}
		report.TimeSince(l.diffRtt+".overall", beforeDiff)
		report.TimeSince(l.diffRtt+".getValuesMulti", beforeDiff)

		if err == nil && diffErr == nil && !reflect.DeepEqual(resp, diffResp) {
			report.Inc("diffs")
			report.Inc("diffs.getValuesMulti")
			log.Printf("[DIFF-getValuesMulti] req: %v\n \torig: %v\n\n\tdiff: %v\n", r, resp, diffResp)
		}
	}
}
開發者ID:surajacharya,項目名稱:quiver,代碼行數:30,代碼來源:workers.go

示例11: sendPrefixes

// Generate and send a random GetValuesSingle request.
func (l *Load) sendPrefixes(client *gen.HFileServiceClient, diff *gen.HFileServiceClient) {
	numKeys := int(math.Abs(rand.ExpFloat64()*10) + 1)
	fullKeys := l.randomKeys(numKeys)
	prefixes := make([][]byte, len(fullKeys))

	for i, v := range fullKeys {
		prefixes[i] = v[:len(v)-2]
	}
	sort.Sort(util.Keys(prefixes))
	r := &gen.PrefixRequest{HfileName: &l.collection, SortedKeys: prefixes}

	before := time.Now()
	resp, err := client.GetValuesForPrefixes(r)
	if err != nil {
		log.Println("[GetValuesForPrefixes] Error fetching value:", err, util.PrettyKeys(prefixes))
	}
	report.TimeSince(l.rtt+".overall", before)
	report.TimeSince(l.rtt+".GetValuesForPrefixes", before)

	if diff != nil {
		beforeDiff := time.Now()
		diffResp, diffErr := diff.GetValuesForPrefixes(r)
		if diffErr != nil {
			log.Println("[GetValuesForPrefixes] Error fetching diff value:", diffErr, util.PrettyKeys(prefixes))
		}
		report.TimeSince(l.diffRtt+".overall", beforeDiff)
		report.TimeSince(l.diffRtt+".GetValuesForPrefixes", beforeDiff)

		if err == nil && diffErr == nil && !reflect.DeepEqual(resp, diffResp) {
			report.Inc("diffs")
			report.Inc("diffs.GetValuesForPrefixes")
			log.Printf("[DIFF-GetValuesForPrefixes] req: %v\n \torig: %v\n\n\tdiff: %v\n", r, resp, diffResp)
		}
	}
}
開發者ID:surajacharya,項目名稱:quiver,代碼行數:36,代碼來源:workers.go

示例12: main

func main() {
	rand.Seed(time.Now().UnixNano())
	// taking "set" literally from task description
	s := map[float64]bool{}
	// pick number of elements to add to set
	n := rand.Intn(11)
	// add random numbers, also throw in an occasional NaN or Inf.
	for i := 0; i < n; i++ {
		switch rand.Intn(10) {
		case 0:
			s[math.NaN()] = true
		case 1:
			s[math.Inf(1)] = true
		default:
			s[rand.ExpFloat64()] = true
		}
	}

	fmt.Print("s:")
	for e := range s {
		fmt.Print(" ", e)
	}
	fmt.Println()
	switch lg, ok, nan := largest(s); {
	case ok && !nan:
		fmt.Println("largest:", lg)
	case ok:
		fmt.Println("largest:", lg, "(NaN present in data)")
	case nan:
		fmt.Println("no largest, all data NaN")
	default:
		fmt.Println("no largest, empty set")
	}
}
開發者ID:travis1230,項目名稱:RosettaCodeData,代碼行數:34,代碼來源:greatest-element-of-a-list-2.go

示例13: Sample

// Generates sample from general Levy-stable distibution.
func Sample(alpha float64, beta float64, mu float64, sigma float64) float64 {
	if beta == 0.0 {
		return symmetric(alpha, mu, sigma)
	}

	v := math.Pi * (rand.Float64() - 0.5)

	w := 0.0
	for w == 0.0 {
		w = rand.ExpFloat64()
	}

	if alpha == 1.0 {
		x := ((0.5*math.Pi+beta*v)*math.Tan(v) -
			beta*math.Log(0.5*math.Pi*w*math.Cos(v)/(0.5*math.Pi+beta*v))) / (0.5 * math.Pi)
		return sigma*x + beta*sigma*math.Log(sigma)/(0.5*math.Pi) + mu
	}

	t := beta * math.Tan(0.5*math.Pi*alpha)
	s := math.Pow(1.0+t*t, 1.0/(2.0*alpha))
	b := math.Atan(t) / alpha
	x := s * math.Sin(alpha*(v+b)) *
		math.Pow(math.Cos(v-alpha*(v+b))/w, (1.0-alpha)/alpha) /
		math.Pow(math.Cos(v), 1.0/alpha)
	return sigma*x + mu
}
開發者ID:pb137,項目名稱:levy,代碼行數:27,代碼來源:sample.go

示例14: makeRandSlice

// Helper function, makes pseudo-random slices.
func makeRandSlice(length uint) (randslice []float64) {
	randslice = make([]float64, length)
	for i := range randslice {
		randslice[i] = rand.ExpFloat64()
	}
	return
}
開發者ID:sguzwf,項目名稱:algorithm,代碼行數:8,代碼來源:vector_test.go

示例15: TestScale

// Creates pseudo-random vectors, does scalar multiplication with pseudo-random
// floats, then checks if the result is correct. It checks both the in-place
// and the non-destructive version.
func TestScale(t *testing.T) {
	var i, j uint
	for i = 0; i < 100; i++ {
		a := makeRandomVector(i)
		x := rand.ExpFloat64()
		b := Scale(a, x)

		for j = 0; j < i; j++ {
			if b.dims[j] != a.dims[j]*x {
				t.Error("Scalar Multiplication failed, ",
					"didn't get expected values.")
				t.Logf("%f * %f != %f", a.dims[j], x, b.dims[j])
			}
		}

		// Test in-place scalar multiplication
		b = a.Copy()
		b.Scale(x)

		for j = 0; j < i; j++ {
			if b.dims[j] != a.dims[j]*x {
				t.Error("In-place Scalar Multiplication failed, ",
					"didn't get expected values.")
				t.Logf("%f * %f != %f", a.dims[j], x, b.dims[j])
			}
		}
	}
}
開發者ID:sguzwf,項目名稱:algorithm,代碼行數:31,代碼來源:vector_test.go


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