Generating A Random Number between 1-20 and keeping a total

I’m trying to make a kids score board where there are 20 icons all with scores behind them between 1 and 20 and a kid chooses an icon, clicks on it to reveal their score, thenthe score is added to their teams running total at the bottom of the window. (There are 2 teams)

The thing i have a problem with is generating the random numbers and also where exactly to drop in the actionscript in the timeline.
I’ve tried different variations of the Math.Floor(Math.Random) but i cant seem to get it to produce the numbers i want!!!:a:

Unfortunatly i cant upload what i have been working on as i dont have net access on my work pc.

Can anyone help? I’m really confused on this one.

A simple formula for generating number between a and b.

ActionScript Code:
[AS]

[FONT=Courier New][LEFT]
function randomBetweenCOLOR=#000000[/COLOR]
[COLOR=#000000]{[/COLOR]
return (a+[COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]floor[/COLOR]COLOR=#000000;[/COLOR]
[COLOR=#000000]}[/COLOR]
[/AS]

[/LEFT]

[/FONT]

use the function in a for loop assigning them to the icons.

i’m sorry but i messed up with the code while editing.

this is the simple function
[AS]
function randomBetween(a,b)
{
return (a+Math.floor(Math.random()*(b+1)));
}

Thanks for the speedy response! I will try it out as soon as I get back.(-:

I dont suppose you would know how i could get it to keep 2 seperate totals at the bottom of the screen do you? 1 total each for Team A and Team B - they would take it in turns to reveal a score and that score would be added to the total for their team.

Cheers.

Hi,
a bit confused about your heading for the problem, but then
this what i have for you , if i’m correct.

This function returns a random number, with given limit.

//----------------------------------------------------------------
// getRangeInclusive
//
// Returns a random number secified within the range including extrem values
// Usage : var myVar = getRangeInclusive(lowerLimit, higherLimit) ;
//
function getRangeInclusive(iMin, iMax) {
var iDiff = iMax-iMin+1;
var v1 = Math.floor(Math.random()*iDiff)+iMin;
return (v1);
}
//----------------------------------------------------------------

Dhiraj

function randomBetween(a, b) {
return (a+Math.floor(Math.random()*(b+1)));
}

var iN = randomBetween(1, 20);

with 1 and 20 as argument , the return value some time was 21.

possible

my earlier function works fine

function getRangeInclusive(iMin, iMax) {
var iDiff = iMax-iMin+1;
var v1 = Math.floor(Math.random()*iDiff)+iMin;
return (v1);
}

Dhiraj

:sure:

Thanks for the response. I can’t get these scripts to work. I’m attaching them to the point in the timeline but i just seem to be not doing something right. When i publish the file to test it it usually comes up with something along the lines of “level2_” instead of the random number between 1 and 20.

Any ideas?

Peter
(Sorry i’m unable to upload the file - if someone would be kind enough to post a sample for me to look at i would be ever greatfull - Thanks!):wink: