mirror of
https://github.com/chaisql/chai.git
synced 2025-10-22 07:09:25 +08:00
Add random function (#514)
This commit is contained in:
@@ -3,6 +3,7 @@ package functions
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
||||
"github.com/genjidb/genji/document"
|
||||
"github.com/genjidb/genji/types"
|
||||
@@ -14,14 +15,15 @@ func MathFunctions() Definitions {
|
||||
}
|
||||
|
||||
var mathFunctions = Definitions{
|
||||
"floor": floor,
|
||||
"abs": abs,
|
||||
"acos": acos,
|
||||
"acosh": acosh,
|
||||
"asin": asin,
|
||||
"asinh": asinh,
|
||||
"atan": atan,
|
||||
"atan2": atan2,
|
||||
"floor": floor,
|
||||
"abs": abs,
|
||||
"acos": acos,
|
||||
"acosh": acosh,
|
||||
"asin": asin,
|
||||
"asinh": asinh,
|
||||
"atan": atan,
|
||||
"atan2": atan2,
|
||||
"random": random,
|
||||
}
|
||||
|
||||
var floor = &ScalarDefinition{
|
||||
@@ -164,3 +166,12 @@ var atan2 = &ScalarDefinition{
|
||||
return types.NewDoubleValue(res), nil
|
||||
},
|
||||
}
|
||||
|
||||
var random = &ScalarDefinition{
|
||||
name: "random",
|
||||
arity: 0,
|
||||
callFn: func(args ...types.Value) (types.Value, error) {
|
||||
randomNum := rand.Int63()
|
||||
return types.NewIntegerValue(randomNum), nil
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user