本文整理汇总了Golang中github.com/jddixon/rnglib_go.PRNG.SomeBytes方法的典型用法代码示例。如果您正苦于以下问题:Golang PRNG.SomeBytes方法的具体用法?Golang PRNG.SomeBytes怎么用?Golang PRNG.SomeBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jddixon/rnglib_go.PRNG
的用法示例。
在下文中一共展示了PRNG.SomeBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doTestSimpleConstructor
func doTestSimpleConstructor(c *C, rng *xr.PRNG, usingSHA1 bool) {
var sha hash.Hash
if usingSHA1 {
sha = sha1.New()
} else {
sha = sha256.New()
}
name := rng.NextFileName(8)
n := rng.SomeBytes(8)
sha.Write(n)
hash0 := sha.Sum(nil)
leaf0, err := NewNLHLeaf(name, hash0)
c.Assert(err, IsNil)
c.Assert(name, Equals, leaf0.Name())
c.Assert(hash0, Equals, leaf0.BinHash())
name2 := name
for name2 == name {
name2 = rng.NextFileName(8)
}
n = rng.SomeBytes(8)
sha.Write(n)
hash1 := sha.Sum(nil)
leaf1, err := NewNLHLeaf(name2, hash1)
c.Assert(err, IsNil)
c.Assert(name2, Equals, leaf1.Name())
c.Assert(hash1, Equals, leaf1.BinHash())
c.Assert(leaf0, Equals, leaf0)
c.Assert(leaf1, Equals, leaf1)
c.Assert(leaf0.Equal(leaf1), Equals, false)
}
示例2: makeLeaf
func makeLeaf(c *C, rng *xr.PRNG, namesSoFar map[string]bool, usingSHA1 bool) (
leaf *NLHLeaf) {
var err error
var name string
for {
name = rng.NextFileName(8)
if !namesSoFar[name] {
namesSoFar[name] = true
break
}
}
n := rng.SomeBytes(8) // 8 quasi-random bytes
var sha hash.Hash
if usingSHA1 {
sha = sha1.New()
} else {
sha = sha256.New()
}
sha.Write(n)
leaf, err = NewNLHLeaf(name, sha.Sum(nil))
c.Assert(err, IsNil)
return
}