Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-07-2004, 02:16 PM   #1
Matsko
New Member
 
Join Date: Mar 2004
Location: Toronto
Posts: 28
Send a message via ICQ to Matsko
Default Does anyone know the actionscript code for RANDOM

Hey

Does anyone know how to make a random actionscript. For Example if you are playing a game where you need to guess a number that is random. Then there would need to be a line of code where the actionscript generates a random number.

Does anyone know how to do that??
Matsko is offline   Reply With Quote
Old 03-07-2004, 03:56 PM   #2
nthpixel
Registered User
 
Join Date: Feb 2004
Location: Honolulu
Posts: 186
Default

Math.random() generates a number between 0 and 1. If you want a random number between 0 and 100, it would be Math.random()*100. Between -50 and 50 would be Math.random()*100 - 50. You get the idea.
nthpixel is offline   Reply With Quote
Old 03-07-2004, 04:07 PM   #3
Matsko
New Member
 
Join Date: Mar 2004
Location: Toronto
Posts: 28
Send a message via ICQ to Matsko
Default

ok good it works, but do you know how to make it equal to a whole number with no decimal places?
Matsko is offline   Reply With Quote
Old 03-07-2004, 04:22 PM   #4
oaker
was here.
 
oaker's Avatar
 
Join Date: Jan 2003
Location: ATL
Posts: 539
Default

Math.floor(random()*100);

For example:

The following code returns a value of 10:

Math.floor(10.5);
__________________
Later,

oaker
www.oaker.com
oaker is offline   Reply With Quote
Old 03-07-2004, 04:46 PM   #5
Matsko
New Member
 
Join Date: Mar 2004
Location: Toronto
Posts: 28
Send a message via ICQ to Matsko
Default

OK, thanx it worked
Matsko is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:23 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.