00:00
00:00
Newgrounds Background Image Theme

joker1222344 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS2 random() problem

12,334 Views | 5 Replies
New Topic Respond to this Topic

AS2 random() problem 2007-09-16 14:43:16


hey, so i want my variable to be a random number between 10 and 20, how would you do this? i found a site with an examplae that said it would be x = Math.random(10)*(20); but that means a random number between 0 and 10 multiplyed by 20 dosent it?
sorry if this is a nooby question but i realy cant find the answer.

Response to AS2 random() problem 2007-09-16 14:46:14


someVar = random(20)+10;

This will make the variable a number between 10 and 20.


postcount +=1;

Newgrounds Photoshop Headquarters || Don't use MS Paint! Use Aviary!

SING US A SING YOU'RE THE PIANO MAN

BBS Signature

Response to AS2 random() problem 2007-09-16 14:54:27


At 9/16/07 02:50 PM, Pyromaniac wrote:
At 9/16/07 02:46 PM, Kart-Man wrote: someVar = random(20)+10;

This will make the variable a number between 10 and 20.
Thats acually between 20-30, between 10 and 20 would be
random(10)+10

Ah, you're right. Whoops. :P
*blames keyboard for mistake*


postcount +=1;

Newgrounds Photoshop Headquarters || Don't use MS Paint! Use Aviary!

SING US A SING YOU'RE THE PIANO MAN

BBS Signature

Response to AS2 random() problem 2007-09-16 14:59:19


if you want it to be a whole integer then wrap it in Math.random()


My Coding Portfolio (updated frequently)

If you stay in bed for long enough it will be socially acceptable to go to bed again

BBS Signature

Response to AS2 random() problem 2007-09-16 15:53:36


At 9/16/07 02:50 PM, Pyromaniac wrote:
At 9/16/07 02:46 PM, Kart-Man wrote: someVar = random(20)+10;

This will make the variable a number between 10 and 20.
Thats acually between 20-30, between 10 and 20 would be
random(10)+10

random(10)+10 is between 0 and 19.
it should be random(10)+11

Response to AS2 random() problem 2007-09-16 15:55:20


sorry (9 and 19) I meant