Generating a random number

Nov 08, 2012

Is there a way to generate a random number to then put into a variable in Storyline?

8 Replies
Steve Flowers

Hey, Mike - 

Without some serious fakery (not really random at all just time varied) you'd need to resort to the JavaScript trigger. Here's an example of rounding:

To generate a random number between 1 and 10 and set a variable to that number, this should work:

var player=GetPlayer();

player.SetVar("randomVariable", Math.floor((Math.random()*10)+1););

//assumes you have a variable named randomVariable in your story

Alexandros Anoyatis

Steve, while we're (more like "you are") at it,

How would you implement a "random grab bag" using Storyline?

Does Storyline retain the value of an internal variable? For example, what happens if you run a second (completely different) JavaScript trigger which references an internal variable in an earlier (first) JS trigger?

Leslie McKerchie

Hello Maria and welcome to E-Learning Heroes :)

Looks like Wendy has popped in to assist you here and I just wanted to share our documentation as well. Could be helpful for you or anyone following along.

If you view an Articulate Storyline 2 course on your local hard drive (or send it to someone else to view on their local hard drive), you'll encounter security restrictions from the computer, web browser, Flash Player, and network that'll cause various features to fail. To properly test your published content and share it with others, upload it to the environment for which it was published. See this article for details.

This discussion is closed. You can start a new discussion or contact Articulate Support.