summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2021-01-12 18:40:06 -0500
committerrsiddharth <s@ricketyspace.net>2021-01-12 18:40:06 -0500
commit2caa4a6e7cd2bd6f053fd0799abf8775f6a5178a (patch)
tree87734dc10802bd85f1e57b3a7a14ed06639ec115
parent6cd41390b1928b8be81d988cd6dfa251fb7dc84a (diff)
lib: update randomBytes
Use randomInt to get the random byte array length.
-rw-r--r--lib/oracle.go16
1 files changed, 2 insertions, 14 deletions
diff --git a/lib/oracle.go b/lib/oracle.go
index 6a229dc..1c548ff 100644
--- a/lib/oracle.go
+++ b/lib/oracle.go
@@ -84,20 +84,8 @@ func randomInt(min, max int64) int64 {
// Randomly generates `min` to `max` bytes.
func randomBytes(min, max int64) []byte {
- var rn *big.Int
- var err error
- for {
- rn, err = rand.Int(rand.Reader, big.NewInt(max+1))
- if err != nil {
- panic(err)
- }
- if rn.Int64() >= min {
- break
- }
- }
-
- bs := make([]byte, rn.Int64())
- _, err = rand.Read(bs)
+ bs := make([]byte, randomInt(min, max))
+ _, err := rand.Read(bs)
if err != nil {
panic(err)
}