7 Replies Latest reply on Dec 9, 2006 5:16 AM by Newsgroup_User

# random() between 10 and 33 ???

hi,

i want to create a button that play's a random frame between 10 and 33, i added this code to the button:
on (release)
{
gotoAndPlay(random(10)+23);
}

but it only paly's frame over 23 and less than 32!!!

what am i doing wrong?
• ###### 1. Re: random() between 10 and 33 ???

IndioDoido wrote:
> hi,
>
> i want to create a button that play's a random frame between 10 and 33, i
> added this code to the button:
> on (release)
> {
> gotoAndPlay(random(10)+23);
> }
>
> but it only paly's frame over 23 and less than 32!!!

Math.floor(Math.random()*10)+23

--
Best Regards

Urami

--

<urami>
If you want to mail me - DO NOT LAUGH AT MY ADDRESS
</urami>
• ###### 2. Re: random() between 10 and 33 ???
urame_> thi one still give 23 to 33, what he need is 10 to 33

It should be:

Math.floor(Math.random()*23)+10
• ###### 3. Re: random() between 10 and 33 ???

ggshow wrote:
> urame_> thi one still give 23 to 33, what he need is 10 to 33
>
> It should be:
>
> Math.floor(Math.random()*23)+10

typo

--
Best Regards

Urami

--

<urami>
If you want to mail me - DO NOT LAUGH AT MY ADDRESS
</urami>
• ###### 4. Re: random() between 10 and 33 ???

thanks for the help guy's!
;-)

but what is the diference between random(10)+23 and Math.floor(Math.random()*23)+10 ??
• ###### 5. Re: random() between 10 and 33 ???
You can use this:
Math.floor(Math.random()*23)+10

You can also use this:
random(23)+10

Both above give the same answer,
random() is AS1 syntax, Math.random() is for AS2.

random(23) will give you a random integer value between 1 to 23.

Math.random() will give you a random value between 0 to 1, it may be a decimal value, etc 0.1234