2019-11-25 20:39:11 +03:00
|
|
|
package testutil
|
2019-08-23 18:50:45 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RandomString returns a random string with the n as its length.
|
2019-11-25 20:39:11 +03:00
|
|
|
func RandomString(n int) string {
|
2019-08-23 18:50:45 +03:00
|
|
|
b := make([]byte, n)
|
|
|
|
for i := range b {
|
2019-11-25 20:39:11 +03:00
|
|
|
b[i] = byte(RandomInt(65, 90))
|
2019-08-23 18:50:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:39:11 +03:00
|
|
|
// RandomInt returns a random integer in [min,max).
|
|
|
|
func RandomInt(min, max int) int {
|
2019-08-23 18:50:45 +03:00
|
|
|
return min + rand.Intn(max-min)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RandomUint256 returns a random Uint256.
|
2019-11-25 20:39:11 +03:00
|
|
|
func RandomUint256() util.Uint256 {
|
|
|
|
str := RandomString(20)
|
2019-08-23 18:50:45 +03:00
|
|
|
return hash.Sha256([]byte(str))
|
|
|
|
}
|
|
|
|
|
|
|
|
// RandomUint160 returns a random Uint160.
|
2019-11-25 20:39:11 +03:00
|
|
|
func RandomUint160() util.Uint160 {
|
|
|
|
str := RandomString(20)
|
2019-08-23 18:50:45 +03:00
|
|
|
return hash.RipeMD160([]byte(str))
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
}
|