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


Golang rand.Seed函數代碼示例

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


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

示例1: init

func init() {
	rand.Seed(time.Now().UnixNano())
	http.HandleFunc("/dirtexto", directorioTexto)
	//http.HandleFunc("/carr", carr)
	http.HandleFunc("/carr", carrVip)
	rand.Seed(time.Now().UnixNano())
}
開發者ID:clicker360,項目名稱:ebfmex-pub,代碼行數:7,代碼來源:wshome.go

示例2: Start

// Start the agent-based model
func (m *Model) Start() error {
	if m.running {
		return errors.New("Model: Start() failed: model already running")
	}
	m.running = true
	if m.RNGRandomSeed {
		rand.Seed(time.Now().UnixNano())
	} else {
		rand.Seed(m.RNGSeedVal)
	}
	timestamp := fmt.Sprintf("%s", time.Now())
	m.popCpPrey = GenerateCpPreyPopulation(m.CpPreyPopulationStart, m.numCpPreyCreated, m.Turn, m.ConditionParams, timestamp)
	m.numCpPreyCreated += m.CpPreyPopulationStart
	m.popVisualPredator = GenerateVPredatorPopulation(m.VpPopulationStart, m.numVpCreated, m.Turn, m.ConditionParams, timestamp)
	m.numVpCreated += m.VpPopulationStart
	if m.Logging {
		go m.log(m.e)
	}
	if m.Visualise {
		go m.vis(m.e)
	}
	time.Sleep(pause)
	go m.run(m.e)
	return nil
}
開發者ID:benjamin-rood,項目名稱:abm-cp,代碼行數:26,代碼來源:model-engine.go

示例3: main

func main() {
	fmt.Println("My favortie number is ", rand.Intn(10))
	fmt.Println("Another random int", rand.Intn(10))

	// Try to Seed with 1
	rand.Seed(1)
	fmt.Println("First sequence")
	for i := 0; i < 10; i++ {
		fmt.Println(rand.Intn(10))
	}

	// Seed again with 1: Numbers are the same
	rand.Seed(1)
	fmt.Println("Second sequence")
	for i := 0; i < 10; i++ {
		fmt.Println(rand.Intn(10))
	}

	// Seed with 2
	rand.Seed(2)
	fmt.Println("Third sequence")
	for i := 0; i < 10; i++ {
		fmt.Println(rand.Intn(10))
	}
}
開發者ID:iplog,項目名稱:gotour,代碼行數:25,代碼來源:main.go

示例4: main

func main() {
	var i = 0
	var buf []byte

	// Repeatable payloads.
	if seed, err := strconv.ParseInt(os.Getenv("SEED"), 10, 32); err == nil {
		rand.Seed(seed)
	} else {
		rand.Seed(defaultSeed)
	}

	sleepTime, err := parseRate(os.Getenv("RATE"))
	if err != nil {
		log.Println("Duration Parsing: ", err)
		log.Println("Continuing w/o duration")
	}

	mlen, err := strconv.ParseInt(os.Getenv("MSGSIZE"), 10, 32)
	if err == nil && mlen > 0 {
		buf = make([]byte, mlen)
	} else {
		log.Println("Unable to parse MSGSIZE, defaulting to MSGSIZE of", defaultMsgSize)
		buf = make([]byte, defaultMsgSize)
	}

	for {
		i++
		if sleepTime > 0 {
			time.Sleep(sleepTime)
		}

		fmt.Println(i, "spews", randStr(buf))
	}
}
開發者ID:apg,項目名稱:spew,代碼行數:34,代碼來源:main.go

示例5: seedPRNG

// seed PRNG to value given, if it is 0 seed to current time
func seedPRNG(seed int64) {
	if seed == 0 {
		rand.Seed(time.Now().UTC().UnixNano())
	} else {
		rand.Seed(seed)
	}
}
開發者ID:theY4Kman,項目名稱:gomandelbrot,代碼行數:8,代碼來源:mandelbrot.go

示例6: main

//pada fungsi ini akan menyimpan data yang digunakan sebagai input
func main() {
	// change "64" to anything else to see
	rand.Seed(8)
	sl := New()
	sl.Set(Int(6), 1)
	sl.Set(Int(5), 2)
	sl.Set(Int(4), 4)
	sl.Set(Int(9), 0)
	sl.draw() // 4-5-6-9-

	valuenya, ketemu := sl.Search(Int(5)) // Found! = 5
	fmt.Println(valuenya)                 //2
	fmt.Println(ketemu)                   // true
	valuenya, ketemu = sl.Search(Int(4))  // Found! = 4
	fmt.Println(valuenya)                 //4
	fmt.Println(ketemu)                   // true
	valuenya, ketemu = sl.Search(Int(6))  // Found! = 6
	fmt.Println(valuenya)                 //1
	fmt.Println(ketemu)                   // true
	valuenya, ketemu = sl.Search(Int(9))  // Found! = 9
	fmt.Println(valuenya)                 //0
	fmt.Println(ketemu)                   // true

	sl.Delete(Int(5))
	sl.draw()                            // 4---6-9-
	valuenya, ketemu = sl.Search(Int(5)) //  No Match Found!
	fmt.Println(valuenya)                //<nil>
	fmt.Println(ketemu)                  // false
	sl.draw()                            // 4---6-9-

	rand.Seed(8)
	s2 := New()
	s2.Set(String("h"), 1)
	s2.Set(String("c"), 2)
	s2.Set(String("i"), 4)
	s2.Set(String("s"), 0)
	s2.draw() // c-h-i-s-

	valuenya, ketemu = s2.Search(String("c")) // Found! = c
	fmt.Println(valuenya)                     //2
	fmt.Println(ketemu)                       // true
	valuenya, ketemu = s2.Search(String("i")) // Found! = i
	fmt.Println(valuenya)                     //4
	fmt.Println(ketemu)                       // true
	valuenya, ketemu = s2.Search(String("s")) // Found! = s
	fmt.Println(valuenya)                     //0
	fmt.Println(ketemu)                       // true
	valuenya, ketemu = s2.Search(String("h")) // Found! = h
	fmt.Println(valuenya)                     //1
	fmt.Println(ketemu)                       // true

	s2.Delete(String("i"))
	s2.draw()                                 // c-h---s-
	valuenya, ketemu = s2.Search(String("i")) // No Match Found!
	fmt.Println(valuenya)                     //<nil>
	fmt.Println(ketemu)                       // false
	s2.draw()                                 // c-h---s-

}
開發者ID:judika,項目名稱:goadsl,代碼行數:60,代碼來源:Skiplist.go

示例7: main

func main() {
	IntSlice := make(IntArr, 12)
	fmt.Print("Awal : ")
	for i := 0; i < 12; i++ {
		rand.Seed(time.Now().UTC().UnixNano())
		IntSlice[i] = rand.Intn(50)
		fmt.Print(IntSlice[i], " ")
	}
	fmt.Println()
	CocktailSort(IntSlice)
	fmt.Print("Sesudah Sorting : ")
	for i := 0; i < 12; i++ {
		fmt.Print(IntSlice[i], " ")
	}
	fmt.Println("\n")

	StringSlice := StringArr{"nama", "saya", "adalah", "alvreda", "ivena"}
	fmt.Print("Awal : ")
	for i := 0; i < 5; i++ {
		fmt.Print(StringSlice[i], " ")
	}
	fmt.Println()
	CocktailSort(StringSlice)
	fmt.Print("Sesudah Sorting : ")
	for i := 0; i < 5; i++ {
		fmt.Print(StringSlice[i], " ")
	}
	fmt.Println("\n")

	Float32Slice := make(Float32Arr, 6)
	fmt.Print("Awal : ")
	for i := 0; i < 6; i++ {
		rand.Seed(time.Now().UTC().UnixNano())
		Float32Slice[i] = rand.Float32()
		fmt.Print(Float32Slice[i], " ")
	}
	fmt.Println()
	CocktailSort(Float32Slice)
	fmt.Print("Sesudah Sorting : ")
	for i := 0; i < 6; i++ {
		fmt.Print(Float32Slice[i], " ")
	}
	fmt.Println("\n")

	Float64Slice := make(Float64Arr, 6)
	fmt.Print("Awal : ")
	for i := 0; i < 6; i++ {
		rand.Seed(time.Now().UTC().UnixNano())
		Float64Slice[i] = rand.Float64()
		fmt.Print(Float64Slice[i], " ")
	}
	fmt.Println()
	CocktailSort(Float64Slice)
	fmt.Print("Sesudah Sorting : ")
	for i := 0; i < 6; i++ {
		fmt.Print(Float64Slice[i], " ")
	}
	fmt.Println()
}
開發者ID:judika,項目名稱:goadsl,代碼行數:59,代碼來源:CocktailSort.go

示例8: TestReserveOneVolume

func TestReserveOneVolume(t *testing.T) {
	topo := setup(topologyLayout)
	rand.Seed(time.Now().UnixNano())
	rand.Seed(1)
	ret, node, vid := topo.RandomlyReserveOneVolume()
	fmt.Println("assigned :", ret, ", node :", node, ", volume id:", vid)

}
開發者ID:asdf20122012,項目名稱:weed-fs,代碼行數:8,代碼來源:topo_test.go

示例9: randomDate

func randomDate() time.Time {
	rand.Seed(time.Now().Unix())
	randomMonth := rand.Intn(108)
	rand.Seed(time.Now().Unix() + int64(randomMonth))
	randomDay := rand.Intn(30)

	return time.Now().AddDate(0, -randomMonth, -randomDay)
}
開發者ID:BearchInc,項目名稱:trails-api,代碼行數:8,代碼來源:trail.go

示例10: TestRetry

func TestRetry(t *testing.T) {
	defer func() {
		timeAfter = time.After
	}()
	rh := &Helper{
		Backoff:   2,
		Retries:   5,
		Delay:     300 * time.Millisecond,
		MaxDelay:  2 * time.Second,
		MaxJitter: 5 * time.Millisecond,
	}
	durations := []time.Duration{
		300 * time.Millisecond,
		600 * time.Millisecond,
		1200 * time.Millisecond,
		2 * time.Second,
		2 * time.Second,
	}
	rand.Seed(1)
	for i := range durations {
		jitter := rand.Int63n(int64(rh.MaxJitter))
		durations[i] += time.Duration(jitter)
	}
	actualRetries := 0
	timeAfter = func(d time.Duration) <-chan time.Time {
		if actualRetries >= len(durations) {
			t.Fatalf("Maximum retry attempts exceeded: got %d", actualRetries)
		}
		if d != durations[actualRetries] {
			t.Errorf("Mismatched duration: got %s; want %s", d, durations[actualRetries])
		}
		actualRetries++
		c := make(chan time.Time, 1)
		c <- time.Now().Add(d)
		return c
	}
	noErrFunc := func() error { return nil }
	rand.Seed(1)
	retries, err := rh.RetryFunc(noErrFunc)
	if err != nil {
		t.Errorf("RetryFunc returned error for non-error function: %s", err)
	}
	if retries != 0 {
		t.Errorf("Mismatched retry attempt count: got %d", retries)
	}
	lastErr := &retryErr{5, true}
	errFunc := func() (err error) {
		return lastErr
	}
	rand.Seed(1)
	retries, err = rh.RetryFunc(errFunc)
	if retries != actualRetries {
		t.Errorf("Mismatched retry attempt count: got %d; want %d", retries, actualRetries)
	}
	if err != lastErr {
		t.Errorf("Unexpected retry error: got %q; want %q", err, lastErr)
	}
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:58,代碼來源:retry_test.go

示例11: init

// Seed sequential random with crypto or math/random and current time
// and generate crypto prefix.
func init() {
	r, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
	if err != nil {
		prand.Seed(time.Now().UnixNano())
	} else {
		prand.Seed(r.Int64())
	}
	globalNUID = &lockedNUID{NUID: New()}
	globalNUID.RandomizePrefix()
}
開發者ID:glycerine,項目名稱:rmq,代碼行數:12,代碼來源:nuid.go

示例12: seedRand

func seedRand() {
	n, err := rand.Int(rand.Reader, big.NewInt(9223372036854775806))
	if err != nil {
		mathrand.Seed(time.Now().UTC().UnixNano())
		return
	}

	mathrand.Seed(n.Int64())
	return
}
開發者ID:pritunl,項目名稱:pritunl-link,代碼行數:10,代碼來源:crypto.go

示例13: initGo

func initGo() {
	fmt.Printf("Initializing Go System (%d threads)\n", numProcs)
	if debug {
		rt.GOMAXPROCS(2)
		rand.Seed(0)
	} else {
		rt.GOMAXPROCS(numProcs)
		rand.Seed(rand.Int63())
	}
}
開發者ID:verdverm,項目名稱:go-pge,代碼行數:10,代碼來源:main.go

示例14: init

func init() {
	// Seed the math/rand RNG from crypto/rand.
	s := make([]byte, 8)
	if _, err := crand.Read(s); err == nil {
		rand.Seed(int64(binary.BigEndian.Uint64(s)))
		return
	}
	// Fall back to system time, boo hoo.
	rand.Seed(time.Now().UnixNano())
}
開發者ID:admiraldolphin,項目名稱:govhack2015,代碼行數:10,代碼來源:db.go

示例15: testSingleProposerUpdateKey

/**
 * Tests that the key is correctly updated in each node's storage system.
 */
func testSingleProposerUpdateKey(doneChan chan bool) {
	key := "b"

	// send first proposal
	randint, _ := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
	rand.Seed(randint.Int64())
	value := rand.Uint32()
	if _, ok := pt.cliMap[1]; !ok {
		LOGE.Println("FAIL: missing node 1")
		doneChan <- false
		return
	}

	pnum, err := pt.GetNextProposalNumber(key, 1)
	reply, err := pt.Propose(key, value, pnum.N, 1)

	if err != nil {
		printFailErr("Propose", err)
		doneChan <- false
		return
	}

	// send second proposal
	randint, _ = crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
	rand.Seed(randint.Int64())
	value = rand.Uint32()

	pnum2, err := pt.GetNextProposalNumber(key, 1)
	// the proposal numbers should be monotonically increasing
	if pnum.N >= pnum2.N {
		LOGE.Println("FAIL: newer proposal number is less than or equal to older proposal number")
		doneChan <- false
		return
	}

	reply, err = pt.Propose(key, value, pnum2.N, 1)
	if err != nil {
		printFailErr("Propose", err)
		doneChan <- false
		return
	}

	if !checkProposeReply(reply, key, value) {
		doneChan <- false
		return
	}

	if !checkGetValueAll(key, value) {
		doneChan <- false
		return
	}

	doneChan <- true
}
開發者ID:thuhujin,項目名稱:Paxos,代碼行數:57,代碼來源:paxostest.go


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