Random Number generator

May 24, 2012

I'm not sure if anyone has done this before - I've seen a number of requests for a random number generator. So I've thrown this together - give it a whirl.... Story is attached.

Lance

49 Replies
Lance G.

Jeannette, you screenr on question banks and random branching was the inspiration for this - it just took about 30 minutes to throw together once I realized it was possible. The question banks were made once, then copied, and the variables changed. You could continue this process for as many digits as you need...

Colin Harm

HI Lance

I have spent the last few days dissmantling your project to understand it, of which I thought I did. I have created a sample cut down using your and Jeanettes technique but for the life of me cannot get it to work.

I am trying to get the project to draw a random number which I can use in a menu slide. Like yours Lance I need to return to the start and generate a new random number each time the process finishes.

I have two problems,

1) When I set the question bank to set the var "Rand" and jump to the next slide on the start of the time line, the number is always 0 (in this sample)

2) If I change the settings on the question bank to jump to the next slide at the end of the time line, it will generate a random number but then when I return to the begining it keeps selecting the same number.

Would you mind having a look to see what I am doing wrong?

Kind Regards

Colin

Lance G.

Hi Colin,

I made a few changes to your story.

In the number bank, somehow you had the advancing set up as a player trigger, rather than a slide trigger. This may have affected the trigger order. I set up both the triggers as slide triggers, and ensured that the variable assignment is first. I also changed the trigger at the end of the slides, to "restart course". Story is attached.

Colin Harm

Thanks for your time Lance.

Yes I now see the difference between a slide and player trigger.

I think the last problem now is that to get it to continue to genrate random numbers is to make it restart the course. I am assuming that means all variables and results are lost. I think this would mean you can only use the random generator once in the course.

I have a Menu (pseudo card game) which is currently using Java to generate a random number 0~9 and launches a scene depending on the results of the number generated. There are 5 scenes and you must visit all 5 scenes prior to completion, I would love to deploy this to ipad but Java inhibits this. Of course I can get around it byu using a conventional menu but that takes the fun out of it.

Colin Harm

I think for your application using a random number generator in Java maybe simpler, then allocate the returned number to a letter using an SL if statement such as if VarNum=1 then SomeotherVar=a and so on.Of course constrain your random number to 26.

For more than one leter then you could use a counter variable to itterate the random number generator and increment the variables.

Colin Harm

Sorry for the delay in replying;

Yes the code is

  var number=Math.floor(Math.random()*25);
GetPlayer().SetVar("RandNum",number);

This will generate a number between 0 and 25 if yo want another number then change the *265 to what you need.

I do not have SL on my home PC so cannot place it in a story line as yet I will have a look at one when I get into the office.

Use a button press to execute the java code.

Ensure you have created a variable called "RandNum"

If you need further numbers in SL you can then use a counter variable to fill in what you need also you can use a if var =0 to generate numbers where needed.

As for creating random letters, words, anything you just make a table that if VarNum = x then SomeVar = y

Hope this helps

Tod Anderson

Lance thanks for this post.  I've just started playing with storyline and the variable options, and this has helped me out

What I wonder now is if I can somehow take two random numbers and perform a mathematical operation on them and have it calculate the correct answer, or if this would be something that would be cleaner using javascript.

Thanks for the help,

Miriam de Jonge

Thanks for the JavaScript Colin, I just used it in a new project and it works like magic. 

Colin Harm said:

Sorry for the delay in replying;

Yes the code is

  var number=Math.floor(Math.random()*25);
GetPlayer().SetVar("RandNum",number);

This will generate a number between 0 and 25 if yo want another number then change the *265 to what you need.

I do not have SL on my home PC so cannot place it in a story line as yet I will have a look at one when I get into the office.

Use a button press to execute the java code.

Ensure you have created a variable called "RandNum"

If you need further numbers in SL you can then use a counter variable to fill in what you need also you can use a if var =0 to generate numbers where needed.

As for creating random letters, words, anything you just make a table that if VarNum = x then SomeVar = y

Hope this helps

Gayla Keesee

I'm looking for a similar concept but instead of numbers, I'm wanting to use colors and have the colors randomly generated so the learner will progress around a board game. I found a discussion about creating a spinner (using Articulate Presenter with the spin animation and a hyperlink to the ending color), etc, but I would have to specify the color the spinner would land on.

I'm using Storyline AND I would prefer to have the colors randomized. I thought I'd have a spin button for the trigger. When the learner lands on the color, he gets a question he must answer in order to proceed, so using the model here, would I have to have two question banks? There's a total of 80 circles (20 of each color). Each color represents a type of math problem (i.e. a different learning objective).

I haven't used the question bank feature in Storyline yet, so I'm a little confused by how to set up the generator. Will be going to the tutorials next.

Parashuram Vhaval

Lance G. said:

Hi Colin,

I made a few changes to your story.

In the number bank, somehow you had the advancing set up as a player trigger, rather than a slide trigger. This may have affected the trigger order. I set up both the triggers as slide triggers, and ensured that the variable assignment is first. I also changed the trigger at the end of the slides, to "restart course". Story is attached.


I just created the same file its working fine, but is there any way doing this differently because I dont want to restart my story everytime

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