chance.js Javascript Library
-
Hello,
I am trying to use the chance.js javascript library.
I have placed it in the Javascript Libraries folder and am testing using various iterations of this:include("chance.js");
The javascript window does not report an error when closing, so i assume it is finding the library file. The monitor is telling me that chance is not defined.
function main() {
let a = chance.d20(); // Rolls a random 20-sided dice
return a;
}Am i doing this correctly? Is it that the chance.js library is incompatible with the isadora javascript engine?
I would appreciate any input here.
Thanks, J
-
I am interested in this to generate random numbers between ranges - but similarly was unable to get the chance.js library to take in Isadora.
I did manage a solution that fits my purpose using 'math.random' function:
// pseudo-random number generator between min and max range // iz_input 1 "trigger" // iz_input 2 "min" // iz_input 3 "max" // iz_output 1 "random" function main() { a = arguments[0]; d = arguments[1]; e = arguments[2]; const minCeiled = Math.ceil(d); const maxFloored = Math.floor(e); { return [ Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled)]; // The maximum is inclusive and the minimum is inclusive } }
best wishes
Russell
-
@bonemap , Thanks for this. I was excited about the chance.js library because it offered random outputs to so many data types which would make things quite efficient here. I will try your method and am sure i could use it to work with other data types.
Next up, I want to try papaparser.js for csv files. It looks promising.