Forum Topic: better method of randomizing.

(75 views • 7 replies)

This topic is 1 page long.

<< < > >>
Crying

masterlink950

Reply To Post Reply & Quote

Posted at: 2/10/09 04:05 PM

masterlink950 LIGHT LEVEL 06

Sign-Up: 01/04/07

Posts: 191

Ok, so this might be a bit basic but I cant stand having to do Math.random and using a freaken math formula to determine randomly what will happen.

Basically I want to know if there is any way to make it so there is a random chance of 1 of 4 events that would occur, if that might be done by like make a variable have a random number from 1-4 or something along those lines, because doing it using math.random is a pain, and I hate using it.
BTW using math.random*4 or whatever its useless, because its still the same thing only im adding a solid number with decimal's after it.


Winking

zuperxtreme

Reply To Post Reply & Quote

Posted at: 2/10/09 04:19 PM

zuperxtreme NEUTRAL LEVEL 08

Sign-Up: 01/02/05

Posts: 1,570

Believe me, Math.random() is the easy way of doing it.


None

masterlink950

Reply To Post Reply & Quote

Posted at: 2/10/09 04:22 PM

masterlink950 LIGHT LEVEL 06

Sign-Up: 01/04/07

Posts: 191

:((((

Is it possible to do a math.random*something to make it easier? i abosutely HATE having to do crap like this:

timer = Math.random();
if (_root.timer>=.50) {
if (timer*100<=25) {
duplicateMovieClip(_root.walls.ball, "ballb"+i, i);
i++;
}
if (timer*100>=75) {
duplicateMovieClip(_root.walls.ball2, "ballb"+i, i);
i++;
}
if (timer*100>=50 and timer*100<=75) {
duplicateMovieClip(_root.walls.ball3, "ballb"+i, i);
i++;
}
}
if (timer*100>=25 and timer*100<=50) {
duplicateMovieClip(_root.walls.ball4, "ballb"+i, i);
i++;
}

That is what I am currently using... and its a giant pain.


None

K-Guare

Reply To Post Reply & Quote

Posted at: 2/10/09 04:24 PM

K-Guare FAB LEVEL 17

Sign-Up: 05/23/08

Posts: 2,327

Math.ceil(Math.random()*4);

Just round it to get rid of the decimal...
A ceiling round makes it from 1-4,
a floor round makes it from 0-3,
and a normal round isn't normally used, but it goes from 0-4.

BBS Signature

None

masterlink950

Reply To Post Reply & Quote

Posted at: 2/10/09 04:27 PM

masterlink950 LIGHT LEVEL 06

Sign-Up: 01/04/07

Posts: 191

At 2/10/09 04:24 PM, K-Guare wrote: Math.ceil(Math.random()*4);

Just round it to get rid of the decimal...
A ceiling round makes it from 1-4,
a floor round makes it from 0-3,
and a normal round isn't normally used, but it goes from 0-4.

Wow this will make things MUCH easier for what I plan to do
THANK YOU!!! lol


None

korded

Reply To Post Reply & Quote

Posted at: 2/10/09 04:30 PM

korded EVIL LEVEL 06

Sign-Up: 02/06/00

Posts: 1,095

I don't know if it's supported in AS3 or not, but I still use random(), usually works for what I am doing.

Whereas.. the line of code..

trace ( random(5) );

..would output a random integer from 0 to 4.


None

K-Guare

Reply To Post Reply & Quote

Posted at: 2/10/09 04:41 PM

K-Guare FAB LEVEL 17

Sign-Up: 05/23/08

Posts: 2,327

At 2/10/09 04:27 PM, masterlink950 wrote: Wow this will make things MUCH easier for what I plan to do
THANK YOU!!! lol

Not sure if you're being sarcastic or not, but,
if you're serious then you're welcome. :3

At 2/10/09 04:30 PM, korded wrote: I don't know if it's supported in AS3 or not, but I still use random(), usually works for what I am doing.

Nope, it's not supported in AS3,
and it's been depreciated since Flash Player 5.
:]

BBS Signature

None

masterlink950

Reply To Post Reply & Quote

Posted at: 2/10/09 04:50 PM

masterlink950 LIGHT LEVEL 06

Sign-Up: 01/04/07

Posts: 191

At 2/10/09 04:41 PM, K-Guare wrote: Not sure if you're being sarcastic or not, but,
if you're serious then you're welcome. :3

Well I am to an extent, I am starting work on a game that will require a lot of randomization as far as npc AI and stuff.


All times are Eastern Standard Time (GMT -5) | Current Time: 10:18 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!