Skip to content

Commit

Permalink
Minor updates to #578
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Jan 19, 2021
1 parent f0097e9 commit cd1b1cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 7 additions & 2 deletions pkg/runtime/core/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ func NumberLowerBoundary(input float64) float64 {
return input / 2
}

func Random(max float64, min float64) float64 {
func RandomDefault() float64 {
rand.Seed(time.Now().UnixNano())
r := rand.Float64()

return rand.Float64()
}

func Random(max float64, min float64) float64 {
r := RandomDefault()
i := r * (max - min + 1)
out := math.Floor(i) + min

Expand Down
5 changes: 1 addition & 4 deletions pkg/stdlib/math/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package math

import (
"context"
"math/rand"
"time"

"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
Expand All @@ -21,8 +19,7 @@ func Rand(_ context.Context, args ...core.Value) (core.Value, error) {
}

if len(args) == 0 {
rand.Seed(time.Now().UnixNano())
return values.NewFloat(rand.Float64()), nil
return values.NewFloat(core.RandomDefault()), nil
}

var max float64
Expand Down

0 comments on commit cd1b1cf

Please sign in to comment.