mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
committed by
Bjørn Erik Pedersen
parent
9cd8fbb332
commit
e40b9fbbcf
@@ -115,6 +115,13 @@ func init() {
|
||||
},
|
||||
)
|
||||
|
||||
ns.AddMethodMapping(ctx.Rand,
|
||||
nil,
|
||||
[][2]string{
|
||||
{"{{ math.Rand }}", "0.6312770459590062"},
|
||||
},
|
||||
)
|
||||
|
||||
ns.AddMethodMapping(ctx.Round,
|
||||
nil,
|
||||
[][2]string{
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user