tpl/math: Add math.Rand template function

Closes #11833
This commit is contained in:
Joe Mooring
2023-12-28 14:25:29 -08:00
committed by Bjørn Erik Pedersen
parent 9cd8fbb332
commit e40b9fbbcf
5 changed files with 71 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"math"
"math/rand"
"reflect"
"sync/atomic"
@@ -157,6 +158,11 @@ func (ns *Namespace) Pow(n1, n2 any) (float64, error) {
return math.Pow(af, bf), nil
}
// Rand returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).
func (ns *Namespace) Rand() float64 {
return rand.Float64()
}
// Round returns the integer nearest to n, rounding half away from zero.
func (ns *Namespace) Round(n any) (float64, error) {
xf, err := cast.ToFloat64E(n)