06-11-2019 12:35
06-11-2019 12:35
I would like to generate a random integer between 0,5 for example on the App using something like:
let pick = Math.randomInt(0,5);
Is there a way to do that? I get Type.error expected a function. I saw somewhere else on here that someone was able to use Math.Random()... I looked over the API but I'm not sure what has to be imported to get access to this function. Thanks.
Answered! Go to the Best Answer.
06-12-2019 08:06
06-12-2019 08:06
I've been using Math.random() with Math.floor() and I've not had to import anything extra.
var diceSize = 4; function roll() { return Math.floor(Math.random() * Math.floor(diceSize)) + 1; }
06-11-2019 13:06
06-11-2019 13:06
Work around: using getRandomValues on the companion then taking the output % 5 to get a random value between 0-5, and then file-transfering that to the App. Overly complicated but works.
06-12-2019 08:06
06-12-2019 08:06
I've been using Math.random() with Math.floor() and I've not had to import anything extra.
var diceSize = 4; function roll() { return Math.floor(Math.random() * Math.floor(diceSize)) + 1; }