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


Golang rand.Uint32函数代码示例

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


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

示例1:

func
u64rand() uint64
{
	a := uint64(rand.Uint32());
	a = (a<<32) | uint64(rand.Uint32());
	a >>= uint(rand.Intn(64));
	return a;
}
开发者ID:8l,项目名称:go-learn,代码行数:8,代码来源:divconst.go

示例2: render

// Continuously update the screen with something interesting
func render() {
	counter := 0
	for {
		w, h := leggo.Dimensions()

		for y := 0; y < h; y += 1 {
			for x := 0; x < w; x += 1 {
				var r, g, b byte
				// Some random things to look at
				switch mode % 8 {
				case 0:
					r = byte(rand.Uint32())
					g = r
					b = r
				case 1:
					r = byte(rand.Uint32())
					g = byte(rand.Uint32())
					b = byte(rand.Uint32())
				case 2:
					r = byte(x * y)
				case 3:
					r = byte(x*y - int(rand.Uint32())%50)
				case 4:
					if x == counter%w {
						r = 255
						g = 255
						b = 255
					}
				case 5:
					if counter%2 == 1 {
						g = 255
					} else {
						r = 255
					}
					time.Sleep(10000)
				case 6:
					if x == w/2 {
						g = 255
					}
					if y == h/2 {
						r = 255
					}
				case 7:
					if x == y {
						b = 255
					}
				}

				leggo.WritePixel(x, y, r, g, b, 0)
			}
		}
		counter += 1
	}
}
开发者ID:shellreef,项目名称:gones,代码行数:55,代码来源:demo.go

示例3: setupHash

func setupHash(size int) {
	emptyBoard[size] = make([]Hash, size*size)
	blackBoard[size] = make([]Hash, size*size)
	whiteBoard[size] = make([]Hash, size*size)
	rand.Seed(int64(size))
	for i := 0; i < size*size; i++ {
		emptyBoard[size][i] = Hash(rand.Uint32())
		blackBoard[size][i] = Hash(rand.Uint32())
		whiteBoard[size][i] = Hash(rand.Uint32())
	}
}
开发者ID:etherealmachine,项目名称:hivemind,代码行数:11,代码来源:zobrist.go

示例4: i64rand

func i64rand() int64 {
	for {
		a := int64(rand.Uint32())
		a = (a << 32) | int64(rand.Uint32())
		a >>= uint(rand.Intn(64))
		if -a != a {
			return a
		}
	}
	return 0 // impossible
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:11,代码来源:modconst.go

示例5: main

func main() {
	if sdl.Init(sdl.INIT_VIDEO) != 0 {
		panic(sdl.GetError())
	}

	defer sdl.Quit()

	screen := sdl.SetVideoMode(400, 300, 32, 0)
	if screen == nil {
		panic(sdl.GetError())
	}

	sdl.WM_SetCaption("Template", "")

	ticker := time.NewTicker(1e9 / 2 /*2 Hz*/)

loop:
	for {
		select {
		case <-ticker.C:
			// Note: For better efficiency, use UpdateRects instead of Flip
			screen.FillRect(nil /*color*/, rand.Uint32())
			//screen.Blit(&sdl.Rect{x,y, 0, 0}, image, nil)
			screen.Flip()

		case event := <-sdl.Events:
			fmt.Printf("%#v\n", event)

			switch e := event.(type) {
			case sdl.QuitEvent:
				break loop
			}
		}
	}
}
开发者ID:remogatto,项目名称:Go-SDL,代码行数:35,代码来源:template.go

示例6: main

func main() {
	flag.Parse()
	//	prime();
	var blocks [1]struct {
		base *byte
		siz  uintptr
	}
	for i := 0; i < 1<<10; i++ {
		if i%(1<<10) == 0 && *chatty {
			println(i)
		}
		b := rand.Int() % len(blocks)
		if blocks[b].base != nil {
			//	println("Free", blocks[b].siz, blocks[b].base);
			runtime.Free(blocks[b].base)
			blocks[b].base = nil
			allocated -= uint64(blocks[b].siz)
			continue
		}
		siz := uintptr(rand.Int() >> (11 + rand.Uint32()%20))
		base := runtime.Alloc(siz)
		//	ptr := uintptr(syscall.BytePtr(base))+uintptr(siz/2);
		//	obj, size, ref, ok := allocator.find(ptr);
		//	if obj != base || *ref != 0 || !ok {
		//		panicln("find", siz, obj, ref, ok);
		//	}
		blocks[b].base = base
		blocks[b].siz = siz
		allocated += uint64(siz)
		//	println("Alloc", siz, base);
		memset(base, 0xbb, siz)
		bigger()
	}
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:34,代码来源:mallocrand.go

示例7: NewMessage

func NewMessage(xid uint32, op, hwtype byte, hwaddr []byte, C, Y, S, G net.IP) (msg *Message, err os.Error) {
	// select a random XID
	if xid == 0 {
		xid = rand.Uint32()
	}
	if len(hwaddr) > 16 {
		err = os.NewError("Invalid DHCP hardware address (too long)")
		return
	}
	msg = &Message{
		Operation:    op,
		HardwareType: hwtype,
		HardwareLen:  byte(len(hwaddr)),
		Xid:          xid,
		// Secs: 0?
		// We default to FLAG_BROADCAST to avoid needing raw packets in Linux
		// This works for EC2, ISC, and possibly others, but no idea where else.
		Flags:     FLAG_BROADCAST,
		ClientIP:  C,
		YourIP:    Y,
		ServerIP:  S,
		GatewayIP: G,
	}
	copy(msg.ClientHWAddr[0:], hwaddr)
	return
}
开发者ID:vonwenm,项目名称:GoDHCP,代码行数:26,代码来源:message.go

示例8: TestStore

func TestStore(t *testing.T) {
	bloom := New()

	for i := 0; i < STORE_RUNS; i++ {
		bloom.Add(string(rand.Uint32()))
	}
}
开发者ID:bluepeppers,项目名称:BloomFilter,代码行数:7,代码来源:bloom_test.go

示例9: randBytes

func randBytes(len int) []byte {
	bytes := make([]byte, len)
	for i := len - 1; i >= 0; i-- {
		bytes[i] = byte(rand.Uint32() % 256)
	}
	return bytes
}
开发者ID:JackeLee,项目名称:drobnosti,代码行数:7,代码来源:rsa.go

示例10: randString

// Create a random string
func randString(strLen int) (randStr string) {
	strChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
	for i := 0; i < strLen; i++ {
		randUint := rand.Uint32()
		pos := randUint % uint32(len(strChars))
		randStr += string(strChars[pos])
	}
	return
}
开发者ID:sudheesh001,项目名称:nodejs,代码行数:10,代码来源:mysql_test.go

示例11: createTempDir

func createTempDir() string {
	once.Do(seedRand)
	result := fmt.Sprintf("/tmp/files_test.%d", rand.Uint32())
	err := os.Mkdir(result, 0700)
	if err != nil {
		panic(fmt.Sprintf("Can't create dir [%s]: %s", result, err))
	}

	return result
}
开发者ID:jacobsa,项目名称:igo,代码行数:10,代码来源:files_test.go

示例12: i16rand

func i16rand() int16 {
	for {
		a := int16(rand.Uint32())
		a >>= uint(rand.Intn(16))
		if -a != a {
			return a
		}
	}
	return 0 // impossible
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:10,代码来源:modconst.go

示例13: i8rand

func i8rand() int8 {
	for {
		a := int8(rand.Uint32())
		a >>= uint(rand.Intn(8))
		if -a != a {
			return a
		}
	}
	return 0 // impossible
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:10,代码来源:modconst.go

示例14: RandNum

// Vygeneruje nahodne cislo v intervalu [2^len, 2^len+1)
func RandNum(len int) *big.Int {
	bytes := randBytes((len + 7) / 8)
	s := byte(len % 8)
	bytes[0] %= 2 << s
	for bytes[0] == 0 {
		bytes[0] = byte(rand.Uint32() % (2 << s))
	}

	return new(big.Int).SetBytes(bytes)
}
开发者ID:JackeLee,项目名称:drobnosti,代码行数:11,代码来源:rsa.go

示例15: i32rand

func i32rand() int32 {
	for {
		a := int32(rand.Uint32())
		a >>= uint(rand.Intn(32))
		if -a != a {
			return a
		}
	}
	return 0 // impossible
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:10,代码来源:modconst.go


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