2019-12-04 12:24:49 +00:00
|
|
|
package random
|
|
|
|
|
|
|
|
import (
|
2024-08-30 12:48:13 +00:00
|
|
|
"math/rand/v2"
|
2019-12-04 12:24:49 +00:00
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2019-12-04 12:24:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// String returns a random string with the n as its length.
|
|
|
|
func String(n int) string {
|
|
|
|
b := make([]byte, n)
|
|
|
|
for i := range b {
|
|
|
|
b[i] = byte(Int(65, 90))
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
2020-03-27 07:14:40 +00:00
|
|
|
// Bytes returns a random byte slice of specified length.
|
|
|
|
func Bytes(n int) []byte {
|
|
|
|
b := make([]byte, n)
|
|
|
|
Fill(b)
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill fills buffer with random bytes.
|
|
|
|
func Fill(buf []byte) {
|
2024-08-30 12:48:13 +00:00
|
|
|
for i := range buf {
|
|
|
|
buf[i] = byte(rand.Int())
|
|
|
|
}
|
2020-03-27 07:14:40 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 09:36:15 +00:00
|
|
|
// Int returns a random integer in [minI,maxI).
|
|
|
|
func Int(minI, maxI int) int {
|
2024-08-30 12:48:13 +00:00
|
|
|
return minI + rand.IntN(maxI-minI)
|
2019-12-04 12:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Uint256 returns a random Uint256.
|
|
|
|
func Uint256() util.Uint256 {
|
|
|
|
str := String(20)
|
|
|
|
return hash.Sha256([]byte(str))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uint160 returns a random Uint160.
|
|
|
|
func Uint160() util.Uint160 {
|
|
|
|
str := String(20)
|
|
|
|
return hash.RipeMD160([]byte(str))
|
|
|
|
}
|