File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package stdlib
33import (
44 "math"
55 "math/rand"
6+ "time"
67
78 "github.com/flipez/rocket-lang/object"
89)
@@ -11,6 +12,10 @@ var mathFunctions = map[string]*object.BuiltinFunction{}
1112var mathProperties = map [string ]* object.BuiltinProperty {}
1213
1314func init () {
15+ // Randomize seed each runtime to avoid predictable results
16+ randSource := rand .NewSource (time .Now ().UnixNano ())
17+ randomizedRand := rand .New (randSource )
18+
1419 mathFunctions ["abs" ] = object .NewBuiltinFunction ("abs" ,
1520 object.MethodLayout {
1621 ReturnPattern : object .Args (object .Arg (object .FLOAT_OBJ )),
@@ -215,7 +220,7 @@ func init() {
215220 ReturnPattern : object .Args (object .Arg (object .FLOAT_OBJ )),
216221 },
217222 func (_ object.Environment , args ... object.Object ) object.Object {
218- return object .NewFloat (rand .Float64 ())
223+ return object .NewFloat (randomizedRand .Float64 ())
219224 },
220225 )
221226 mathFunctions ["remainder" ] = object .NewBuiltinFunction ("remainder" ,
You can’t perform that action at this time.
0 commit comments