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


Golang PRNG.Int63方法代码示例

本文整理汇总了Golang中github.com/jddixon/rnglib_go.PRNG.Int63方法的典型用法代码示例。如果您正苦于以下问题:Golang PRNG.Int63方法的具体用法?Golang PRNG.Int63怎么用?Golang PRNG.Int63使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jddixon/rnglib_go.PRNG的用法示例。


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

示例1: makeEntryData

func (s *XLSuite) makeEntryData(c *C, rng *xr.PRNG, whichSHA int) (
	t int64, key, nodeID []byte, src, path string) {

	t = rng.Int63() // timestamp
	var length int
	switch whichSHA {
	case xu.USING_SHA1:
		length = xu.SHA1_BIN_LEN
	case xu.USING_SHA2:
		length = xu.SHA2_BIN_LEN
	case xu.USING_SHA3:
		length = xu.SHA3_BIN_LEN
		// XXX DEFAULT = ERROR
	}
	key = make([]byte, length)
	rng.NextBytes(key)

	nodeID = make([]byte, length)
	rng.NextBytes(nodeID)

	src = rng.NextFileName(32) // 32 is max len
	path = rng.NextFileName(32)
	for strings.Contains(path, ".") { // that crude fix
		path = rng.NextFileName(32)
	}
	return
}
开发者ID:jddixon,项目名称:upax_go,代码行数:27,代码来源:entry_test.go

示例2: makeARegCluster

// Make a RegCluster for test purposes.  Cluster member names are guaranteed
// to be unique but the name of the cluster itself may not be.
//
// THIS IS THE REGISTRY'S VIEW OF A CLUSTER
func (s *XLSuite) makeARegCluster(c *C, rng *xr.PRNG, epCount, size uint32) (
	rc *RegCluster) {

	var err error
	c.Assert(MIN_CLUSTER_SIZE <= size && size <= MAX_CLUSTER_SIZE, Equals, true)

	attrs := uint64(rng.Int63())
	name := rng.NextFileName(8) // no guarantee of uniqueness
	id := s.makeANodeID(c, rng)

	rc, err = NewRegCluster(name, id, attrs, size, epCount)
	c.Assert(err, IsNil)

	for count := uint32(0); count < size; count++ {
		cm := s.makeAClientInfo(c, rng, epCount)
		for {
			if _, ok := rc.MembersByName[cm.GetName()]; ok {
				// name is in use, so try again
				cm = s.makeAClientInfo(c, rng, epCount)
			} else {
				err = rc.AddMember(cm)
				c.Assert(err, IsNil)
				break
			}
		}
	}
	return
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:32,代码来源:gocheck_test.go

示例3: makeAMemberInfo

func (s *XLSuite) makeAMemberInfo(c *C, rng *xr.PRNG) *xcl.MemberInfo {
	attrs := uint64(rng.Int63())
	peer, err := xn.NewPeer(
		rng.NextFileName(8),
		s.makeANodeID(c, rng),
		&s.makeAnRSAKey(c).PublicKey,
		&s.makeAnRSAKey(c).PublicKey,
		nil, // overlays
		nil) // XXX CONNECTORS
	c.Assert(err, IsNil)
	return &xcl.MemberInfo{
		Attrs: attrs,
		Peer:  peer,
	}
} // GEEP
开发者ID:jddixon,项目名称:xlReg_go,代码行数:15,代码来源:gocheck_test.go

示例4: makeAMemberInfo

func (s *XLSuite) makeAMemberInfo(c *C, rng *xr.PRNG) *xcl.MemberInfo {
	attrs := uint64(rng.Int63())
	bn, err := xn.NewBaseNode(
		rng.NextFileName(8),
		s.makeANodeID(c, rng),
		&s.makeAnRSAKey(c).PublicKey,
		&s.makeAnRSAKey(c).PublicKey,
		nil) // overlays
	c.Assert(err, IsNil)

	asPeer := &xn.Peer{
		BaseNode: *bn,
	}
	return &xcl.MemberInfo{
		Attrs: attrs,
		Peer:  asPeer,
	}
}
开发者ID:jddixon,项目名称:upax_go,代码行数:18,代码来源:gocheck_test.go

示例5: makeAClientInfo

func (s *XLSuite) makeAClientInfo(c *C, rng *xr.PRNG, epCount uint32) *ClientInfo {
	attrs := uint64(rng.Int63())
	var myEnds []string
	for i := uint32(0); i < epCount; i++ {
		myEnds = append(myEnds, "127.0.0.1:0")
	}
	bn, err := xn.NewBaseNode(
		rng.NextFileName(8),
		s.makeANodeID(c, rng),
		&s.makeAnRSAKey(c).PublicKey,
		&s.makeAnRSAKey(c).PublicKey,
		nil) // overlays
	c.Assert(err, IsNil)
	return &ClientInfo{
		Attrs:    attrs,
		MyEnds:   myEnds,
		BaseNode: *bn,
	}
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:19,代码来源:gocheck_test.go

示例6: makeACluster

func (s *XLSuite) makeACluster(c *C, rng *xr.PRNG, epCount, size uint32) (
	rc *reg.RegCluster) {

	var err error
	c.Assert(1 < size && size <= 64, Equals, true)

	attrs := uint64(rng.Int63())
	name := rng.NextFileName(8) // no guarantee of uniqueness
	id := s.makeANodeID(c, rng)

	rc, err = reg.NewRegCluster(name, id, attrs, size, epCount)
	c.Assert(err, IsNil)

	for count := uint32(0); count < size; count++ {
		cm := s.makeAMemberInfo(c, rng)
		for {
			if _, ok := rc.MembersByName[cm.Peer.GetName()]; ok {
				// name is in use, so try again
				cm = s.makeAMemberInfo(c, rng)
			} else {
				// copy the connector list as strings
				myEnds := make([]string, 0, 0)
				for endCount := 0; endCount < int(size); endCount++ {
					thisEnd := cm.Peer.GetConnector(endCount).String()
					myEnds = append(myEnds, thisEnd)
				}
				asClient := &reg.ClientInfo{
					Attrs:    cm.Attrs,
					MyEnds:   myEnds,
					BaseNode: cm.Peer.BaseNode,
				}
				err = rc.AddMember(asClient)
				break
			}
		}
	}
	return
}
开发者ID:jddixon,项目名称:upax_go,代码行数:38,代码来源:gocheck_test.go

示例7: doTestRegexes

func (s *XLSuite) doTestRegexes(c *C, rng *xr.PRNG, whichSHA int) {
	t := rng.Int63()
	var length int
	switch whichSHA {
	case xu.USING_SHA1:
		length = xu.SHA1_BIN_LEN
	case xu.USING_SHA2:
		length = xu.SHA2_BIN_LEN
	case xu.USING_SHA3:
		length = xu.SHA3_BIN_LEN
		// XXX DEFAULT = ERROR
	}
	key := make([]byte, length)
	rng.NextBytes(key)
	hexKey := hex.EncodeToString(key)

	nodeID := make([]byte, length)
	rng.NextBytes(nodeID)
	hexNodeID := hex.EncodeToString(nodeID)

	src := rng.NextFileName(32) // 32 is max len
	path := rng.NextFileName(32)
	for strings.Contains(path, ".") { // XXX a crude fix
		path = rng.NextFileName(32)
	}

	expected := fmt.Sprintf("%d %s %s \"%s\" %s",
		t, hexKey, hexNodeID, src, path)

	switch whichSHA {
	case xu.USING_SHA1:
		c.Assert(bodyLine1RE.MatchString(expected), Equals, true)
		groups := bodyLine1RE.FindStringSubmatch(expected)
		c.Assert(groups, Not(IsNil))
		c.Assert(len(groups), Equals, 6) // 5 fields + match on all

		c.Assert(bodyLine3RE.MatchString(expected), Equals, false)

	case xu.USING_SHA2:
		c.Assert(bodyLine2RE.MatchString(expected), Equals, true)
		groups := bodyLine2RE.FindStringSubmatch(expected)
		c.Assert(groups, Not(IsNil))
		c.Assert(len(groups), Equals, 6) // 5 fields + match on all

		c.Assert(bodyLine1RE.MatchString(expected), Equals, false)

	case xu.USING_SHA3:
		// DEBUG
		if !bodyLine3RE.MatchString(expected) {
			fmt.Printf("DOESN'T MATCH PATTERN: %s\n", expected)
		}
		// END
		c.Assert(bodyLine3RE.MatchString(expected), Equals, true)
		groups := bodyLine3RE.FindStringSubmatch(expected)
		c.Assert(groups, Not(IsNil))
		c.Assert(len(groups), Equals, 6)

		c.Assert(bodyLine1RE.MatchString(expected), Equals, false)
		// XXX DEFAULT = ERROR
	}
}
开发者ID:jddixon,项目名称:upax_go,代码行数:61,代码来源:regular_test.go


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