neoneo-go/pkg/util/test_util.go
Evgeniy Kulikov 67cbcac643 Fix typos (#133)
* Fix typos

* revert chains/unit_testnet

* revert chains

* fix review comments (thx @AlexVanin)
2019-02-13 18:01:10 +00:00

45 lines
857 B
Go

package util
import (
"crypto/sha256"
"math/rand"
"time"
"golang.org/x/crypto/ripemd160"
)
// RandomString returns a random string with the n as its length.
func RandomString(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = byte(RandomInt(65, 90))
}
return string(b)
}
// RandomInt returns a random integer between min and max.
func RandomInt(min, max int) int {
return min + rand.Intn(max-min)
}
// RandomUint256 returns a random Uint256.
func RandomUint256() Uint256 {
str := RandomString(20)
h := sha256.Sum256([]byte(str))
return Uint256(h)
}
// RandomUint160 returns a random Uint160.
func RandomUint160() Uint160 {
str := RandomString(20)
ripemd := ripemd160.New()
ripemd.Write([]byte(str))
h := ripemd.Sum(nil)
v, _ := Uint160DecodeBytes(h)
return v
}
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}