Skip to content

Commit

Permalink
[#187531276] Bug fix: randomNormal function bug fix when encountering…
Browse files Browse the repository at this point in the history
… string arguments

* We coerce the arguments passed to all the randomGen functions to numbers since that is what they expect
  • Loading branch information
bfinzer committed May 17, 2024
1 parent a46f293 commit 2b012d2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions v3/src/models/formula/functions/other-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ export const otherFunctions = {
numOfRequiredArguments: 0,
isRandomFunction: true,
// Nothing to do here, Random.float() has exactly the same signature as CODAP V2 random() function.
evaluate: (...args: FValue[]) => randomGen.float(...args as number[])
evaluate: (...args: FValue[]) => randomGen.float(...args.map(arg=>Number(arg)))
},

// randomNormal(mean, standard_deviation) Returns a random number drawn from a normal distribution which, by default,
// has a mean of 0 and a standard deviation of 1.
randomNormal: {
numOfRequiredArguments: 0,
isRandomFunction: true,
// Nothing to do here, Random.normal() has exactly the same signature as CODAP V2 randomNormal() function.
// We coerce the arguments to numbers.
// randomGen.normal() has exactly the same signature as CODAP V2 randomNormal() function.
evaluate: (...args: FValue[]) => {
return randomGen.normal(...args as number[])()
return randomGen.normal(...args.map(arg=>Number(arg)))()
}
},

Expand All @@ -44,9 +45,9 @@ export const otherFunctions = {
randomBinomial: {
numOfRequiredArguments: 0,
isRandomFunction: true,
// Nothing to do here, Random.binomial() has exactly the same signature as CODAP V2 randomBinomial() function.
// Nothing to do here, randomGen.binomial() has exactly the same signature as CODAP V2 randomBinomial() function.
evaluate: (...args: FValue[]) => {
return randomGen.binomial(...args as number[])()
return randomGen.binomial(...args.map(arg=>Number(arg)))()
}
},

Expand Down

0 comments on commit 2b012d2

Please sign in to comment.