mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
52fa41a12a
* added account_state + changed ECPoint to PublicKey * account state persist * in depth test for existing accounts. * implemented GetTransaction. * added enrollment TX * added persist of accounts and unspent coins * bumped version -> 0.32.0
45 lines
858 B
Go
45 lines
858 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)
|
|
}
|
|
|
|
// RamdomInt returns a ramdom integer betweeen 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())
|
|
}
|