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


Golang rand.Uint32函数代码示例

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


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

示例1: rand32

func rand32() uint32 {
	var result uint32 = 0
	result = rand.Uint32()
	result <<= 16
	result |= rand.Uint32()
	return result
}
开发者ID:NatkungZ,项目名称:PRNG,代码行数:7,代码来源:mvc.go

示例2: TestFtoaRandom

func TestFtoaRandom(t *testing.T) {
	N := int(1e4)
	if testing.Short() {
		N = 100
	}
	t.Logf("testing %d random numbers with fast and slow FormatFloat", N)
	for i := 0; i < N; i++ {
		bits := uint64(rand.Uint32())<<32 | uint64(rand.Uint32())
		x := math.Float64frombits(bits)

		shortFast := FormatFloat(x, 'g', -1, 64)
		SetOptimize(false)
		shortSlow := FormatFloat(x, 'g', -1, 64)
		SetOptimize(true)
		if shortSlow != shortFast {
			t.Errorf("%b printed as %s, want %s", x, shortFast, shortSlow)
		}

		prec := rand.Intn(12) + 5
		shortFast = FormatFloat(x, 'e', prec, 64)
		SetOptimize(false)
		shortSlow = FormatFloat(x, 'e', prec, 64)
		SetOptimize(true)
		if shortSlow != shortFast {
			t.Errorf("%b printed as %s, want %s", x, shortFast, shortSlow)
		}
	}
}
开发者ID:pjump,项目名称:gcc,代码行数:28,代码来源:ftoa_test.go

示例3: packet

func packet(raddr net.IP) []byte {
	ip := &layers.IPv4{
		Version:           0x4,
		TOS:               0x0,
		TTL:               0x40,
		Protocol:          layers.IPProtocolTCP,
		SrcIP:             net.ParseIP(os.Args[2]),
		DstIP:             raddr,
		WithRawINETSocket: true,
	}
	rand.Seed(time.Now().UnixNano())
	tcp := &layers.TCP{
		SrcPort:    layers.TCPPort(rand.Uint32()),
		DstPort:    0x50,
		Seq:        rand.Uint32(),
		DataOffset: 0x5,
		SYN:        true,
		Window:     0xaaaa,
	}
	tcp.SetNetworkLayerForChecksum(ip)
	buf := gopacket.NewSerializeBuffer()
	opts := gopacket.SerializeOptions{true, true}
	check(gopacket.SerializeLayers(buf, opts, ip, tcp))
	return buf.Bytes()
}
开发者ID:nhooyr,项目名称:dos,代码行数:25,代码来源:main.go

示例4: TestGobNormal

func TestGobNormal(t *testing.T) {
	h, err := NewHLL(10)
	assert.Nil(t, err)
	h.ToNormal()

	var i float64
	for i = 0; i <= 100000; i++ {
		h.Add(fmt.Sprintf("%d-%d", i, rand.Uint32()))
	}
	assert.Equal(t, h.format, NORMAL, "Not using normal mode")

	c := h.Cardinality()
	errorRate := 1.04 / math.Sqrt(float64(h.m1))
	checkErrorBounds(t, c, i, errorRate)
	var buf bytes.Buffer
	err = gob.NewEncoder(&buf).Encode(h)
	assert.Nil(t, err)
	var h2 HLL
	err = gob.NewDecoder(&buf).Decode(&h2)
	assert.Nil(t, err)

	assert.Equal(t, h2.format, NORMAL, "Not using normal mode")
	assert.Equal(t, c, h2.Cardinality())

	for i = 0; i <= 40000; i++ {
		v := rand.Uint32()
		h.Add(fmt.Sprintf("%d-%d", i, v))
		h2.Add(fmt.Sprintf("%d-%d", i, v))
	}

	assert.Equal(t, h.Cardinality(), h2.Cardinality())
}
开发者ID:jbowles,项目名称:gohll,代码行数:32,代码来源:gob_test.go

示例5: KeyPair

func KeyPair() (privateKey, publicKey uint64) {
	a := uint64(rand.Uint32())
	b := uint64(rand.Uint32()) + 1
	privateKey = (a << 32) | b
	publicKey = PublicKey(privateKey)
	return
}
开发者ID:miffa,项目名称:crypto,代码行数:7,代码来源:dh64.go

示例6: generateTransactionId

func generateTransactionId() [3]uint32 {
	return [3]uint32{
		rand.Uint32(),
		rand.Uint32(),
		rand.Uint32(),
	}
}
开发者ID:vanstee,项目名称:stun-go,代码行数:7,代码来源:header.go

示例7: spammer

func spammer() {
	hostname := "SpamSpamSpam      SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam"

	broadcastConn := openUDPConnOrDie(spamerPort)
	defer broadcastConn.Close()

	addr, err := net.ResolveUDPAddr("udp4", net.IPv4bcast.String()+":"+strconv.Itoa(receiverPort))
	if err != nil {
		log.Fatalf("Cannot resolve broadcast receiver address: %s", err)
	}

	hardwareAddr := make([]byte, 6)
	broadcastCommonData := append(hardwareAddr, byte(len(hostname)))
	broadcastCommonData = append(broadcastCommonData, ([]byte)(hostname)...)

	timestampBuff := make([]byte, 4) //32!!!!
	ticker := time.NewTicker(spamInterval)
	for _ = range ticker.C {
		unixTimestamp := Timestamp(time.Now().Unix())
		endian.PutUint32(timestampBuff, uint32(unixTimestamp))
		endian.PutUint32(broadcastCommonData, rand.Uint32())
		endian.PutUint32(broadcastCommonData[2:], rand.Uint32())
		copy(broadcastCommonData[7:], []byte(net.HardwareAddr(broadcastCommonData[0:6]).String()))
		_, err = broadcastConn.WriteTo(append(broadcastCommonData, timestampBuff...), addr)
		if err != nil {
			log.Fatalf("Unable to broadcast SPAM: %s", err)
		}
	}
}
开发者ID:Skipor,项目名称:networks_lab1,代码行数:29,代码来源:main.go

示例8: CheapRandString16

func CheapRandString16() string {
	if !seeded {
		rand.Seed(time.Now().UnixNano())
		seeded = true
	}
	return fmt.Sprintf("%x%x", rand.Uint32(), rand.Uint32())
}
开发者ID:acsellers,项目名称:thoreni,代码行数:7,代码来源:rand_strings.go

示例9: TestReadWriteAtom

func TestReadWriteAtom(t *testing.T) {
	ctx := NewCtx(1)
	a := ctx.newAtom()

	copy(a.data, []byte{'a'})
	testReadWriteAtom(t, a)
	copy(a.data, []byte{'0'})
	testReadWriteAtom(t, a)
	copy(a.data, []byte{'\x00'})
	testReadWriteAtom(t, a)

	for i := 0; i < 100; i++ {
		copy(a.data, []byte{byte(mathrand.Uint32())})
		testReadWriteAtom(t, a)
	}

	ctx2 := NewCtx(2)
	a2 := ctx2.newAtom()
	copy(a2.data, []byte{'a', 'a'})
	testReadWriteAtom(t, a)
	copy(a2.data, []byte{'0', '0'})
	testReadWriteAtom(t, a)
	copy(a2.data, []byte{'\x00', '\x00'})
	testReadWriteAtom(t, a)

	for i := 0; i < 100; i++ {
		r := mathrand.Uint32()
		copy(a.data, []byte{byte(r), byte(r >> 8)})
		testReadWriteAtom(t, a)
	}
}
开发者ID:pennello,项目名称:go_steg,代码行数:31,代码来源:rw_test.go

示例10: intPairArray

func intPairArray(n int) []KeyValPair {
	a := make([]KeyValPair, n)
	for i := 0; i < n; i++ {
		a[i] = KeyValPair{rand.Uint32(), rand.Uint32()}
	}
	return a
}
开发者ID:dgraph-io,项目名称:experiments,代码行数:7,代码来源:benchhash.go

示例11: CreateClient

func CreateClient(uid uint64, password string) {
RECONNECTION:
	//tcpAddr, err := net.ResolveTCPAddr("tcp", "192.168.20.51:9100")
	tcpAddr, err := net.ResolveTCPAddr("tcp", "112.74.66.141:9100")
	//tcpAddr, err := net.ResolveTCPAddr("tcp", "112.74.66.141:9100")
	//tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:9100")
	if err != nil {
		fmt.Println(err)
		return
	}
	clientIP := fmt.Sprintf("127.%v.%v.%v:0", rand.Uint32()%255, rand.Uint32()%255, rand.Uint32()%255)
	locAddr, err := net.ResolveTCPAddr("tcp", clientIP)
	if err != nil {
		panic(err)
	}
	connClient, err := net.DialTCP("tcp", locAddr, tcpAddr)
	if err != nil {
		fmt.Println(err)
		return
	}
	client := &Client{
		conn: connClient,
		uid:  uid,
	}
	log.Println("connect start:", *client)
	err = client.recvPkg()
	if err != nil && err != io.EOF {
		log.Println(err, *client)
		return
		goto RECONNECTION
	} else if err != nil {
		panic(err)
	}
	log.Println("connect end:", *client)
	// 先登录
	client.execArgs("10102", uid, password)
	client.recvPkg()
	cur_count++
	go client.run()

	//select {}
	time.Sleep(3 * time.Minute)
	for {
		// 跑业务
		//second := time.Duration(rand.Uint32()%150) + 30
		time.Sleep(time.Second * 60)
		if client.sid == 0 {
			continue
		}
		uid := int(rand.Uint32())%cur_count + MIN_UID
		g_rwMutex.RLock()
		_, ok := g_client_map[uint64(uid)]
		g_rwMutex.RUnlock()
		if ok {
			client.execArgs("30101", uid)
		}
	}
	client.Close()
}
开发者ID:sunyuantao,项目名称:windows,代码行数:59,代码来源:client.go

示例12: testDuelingProposal

func testDuelingProposal(doneChan chan bool) {
	key := "a"
	randint, _ := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
	rand.Seed(randint.Int64())
	value1 := rand.Uint32()
	value2 := rand.Uint32()
	if _, ok := pt.cliMap[1]; !ok {
		LOGE.Println("FAIL: missing node 1")
		doneChan <- false
		return
	}
	// retChan := make(chan *paxosrpc.ProposeReply, 10)

	pnum1, err1 := pt.GetNextProposalNumber(key, 1)
	pnum2, err2 := pt.GetNextProposalNumber(key, 1)

	fmt.Println("Proposing:", key, value1, pnum1.N)
	// reply1, err := pt.ProposeForDueling(key, value1, pnum1.N, 1, retChan)
	reply1, err1 := pt.Propose(key, value1, pnum1.N, 1)
	fmt.Println(reply1.V)
	fmt.Println("Proposing:", key, value2, pnum2.N)
	reply2, err2 := pt.Propose(key, value2, pnum2.N, 1)
	// reply2, err := pt.ProposeForDueling(key, value2, pnum2.N, 1, retChan)
	fmt.Println(reply2.V)

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

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

	if !checkProposeReply(reply1, key, value1) {
		doneChan <- false
		return
	}
	fmt.Println("check 1 pass")
	if !checkGetValueAll(key, value2) {
		doneChan <- false
		return
	}

	// if !checkProposeReply(reply2, key, value2) {
	// 	doneChan <- false
	// 	return
	// }

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

	doneChan <- true
}
开发者ID:thuhujin,项目名称:Paxos,代码行数:59,代码来源:paxostest.go

示例13: BenchmarkMap

func (s *PostingSuite) BenchmarkMap(c *C) {
	postings := make(fakePostings, c.N)
	for i := 0; i <= c.N; i++ {
		doctype := rand.Uint32()%100 + 1
		docid := rand.Uint32()%100 + 1
		postings.Add(doctype, docid)
	}
}
开发者ID:pietergvw,项目名称:superfastmatch,代码行数:8,代码来源:encoding_test.go

示例14: BenchmarkWriteControl

func BenchmarkWriteControl(b *testing.B) {
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			rand.Uint32()
			rand.Uint32()
		}
	})
}
开发者ID:dgraph-io,项目名称:experiments,代码行数:8,代码来源:benchhash_test.go

示例15: TestEncodeBigInt

func TestEncodeBigInt(t *testing.T) {
	assertEnc(t, hexChars, 15, "f")
	assertEnc(t, hexChars, 16, "10")
	for i := 0; i < 1000; i++ {
		assertSync(t, hexChars, rand.Uint32())
		assertSync(t, flumChars, rand.Uint32())
	}
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:8,代码来源:utils_test.go


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