File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ package global
33import (
44 "bytes"
55 "context"
6+ "crypto/rand"
67 "embed"
7- "math/rand "
8+ "math/big "
89 "net"
910 "reflect"
1011 "time"
@@ -49,8 +50,8 @@ func initBuiltInFunc(runtime *goja.Runtime) {
4950 Description : "Rand returns a random byte slice of length n" ,
5051 FuncDecl : func (n int ) []byte {
5152 b := make ([]byte , n )
52- for i := range b {
53- b [ i ] = byte ( rand . Intn ( 255 ))
53+ if _ , err := rand . Read ( b ); err != nil {
54+ return nil
5455 }
5556 return b
5657 },
@@ -61,7 +62,11 @@ func initBuiltInFunc(runtime *goja.Runtime) {
6162 Signatures : []string {"RandInt() int" },
6263 Description : "RandInt returns a random int" ,
6364 FuncDecl : func () int64 {
64- return rand .Int63 ()
65+ n , err := rand .Int (rand .Reader , new (big.Int ).SetInt64 (1 << 63 - 1 ))
66+ if err != nil {
67+ return 0
68+ }
69+ return n .Int64 ()
6570 },
6671 })
6772
You can’t perform that action at this time.
0 commit comments