Storyline Random Number - Rounding Method
Nov 06, 2020
Prior to the addition of the Random Number variable, I used JavaScript code to generate a random number in Storyline. Just as Storyline presents the random number as a whole integer (without decimals), I also used JavaScript to round the random number to a whole integer.
In JavaScript, there are 3 methods that can be used to round numbers to the nearest integer:
- Math.round( ) rounds the number to the nearest integer (up or down)
- Math.ceil( ) rounds the number up to the nearest integer
- Math.floor( ) rounds the number down to the nearest integer
Question to Articulate Staff - are any of these methods used to round the random number variable in Storyline? If so, which method is used? I am trying to get a sense of the differences between generating a random number using the functionality in Storyline vs. custom JavaScript code.
Thanks in advance for your help!
2 Replies
Hi Bridget,
Happy to provide a bit more clarity here!
While I can't share what exactly is happening behind the scenes or the "secret sauce," an outcome that is similar to the Random Number Variable functionality in Storyline is this JavaScript function:
Math.floor(Math.random() * 10);
Instead of returning an integer between 0 and 1, the example above will return a random whole integer between 0 and 9. The outcome you see when using this example produces similar results to the Random Number Variable workflow in Storyline.
I hope that helps and please let us know if you have any questions!
Thanks for that information, Vincent!
This discussion is closed. You can start a new discussion or contact Articulate Support.