summaryrefslogtreecommitdiffstats
path: root/lib/oracle.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2021-01-12 18:34:04 -0500
committerrsiddharth <s@ricketyspace.net>2021-01-12 18:34:04 -0500
commit6cd41390b1928b8be81d988cd6dfa251fb7dc84a (patch)
tree91e8d8cf10a66fd06121f640995df744ff7d6cfe /lib/oracle.go
parent19f8b1df519f4cb20e4b6060d6296d9d501a57f4 (diff)
lib: add randomInt
Diffstat (limited to 'lib/oracle.go')
-rw-r--r--lib/oracle.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/oracle.go b/lib/oracle.go
index 47d850c..6a229dc 100644
--- a/lib/oracle.go
+++ b/lib/oracle.go
@@ -63,6 +63,25 @@ func OracleAESEncryptECB(in []byte) []byte {
return AESEncryptECB(append(in, Base64ToBytes(oracleUnknown)...), oracleKey)
}
+// Return a random number from range [min, max]
+func randomInt(min, max int64) int64 {
+ if min >= max {
+ panic("randomInt: min cannot be >= max!")
+ }
+
+ 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 {
+ return rn.Int64()
+ }
+ }
+}
+
// Randomly generates `min` to `max` bytes.
func randomBytes(min, max int64) []byte {
var rn *big.Int