Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-02-2011, 04:56 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Random?

How would I make a random integer?
Like for chance... It needs to say a RANDOM number.
PHP Code:
function onActionGrab()
{
this.chat = ??? -Random Stuff Here- ???
} 
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 03-02-2011, 05:14 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
random(lownumber,highnumber);
combined with int(val);

To get a random int between 0 and 5, for example:
int(random(0,5.9999));

I suggest putting the 9's there for any of the integer-related random numbers, otherwise the chances of the high number showing up are slim to none.
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #3  
Old 03-02-2011, 05:15 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
this.chat = int(random(0,100)+.5);
Reply With Quote
  #4  
Old 03-02-2011, 05:19 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Quote:
Originally Posted by DustyPorViva View Post
this.chat = int(random(0,100)+.5);
whats the +.5 for?
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #5  
Old 03-02-2011, 05:36 AM
Cloven Cloven is offline
Delteria
Cloven's Avatar
Join Date: Dec 2006
Location: Florida, United States
Posts: 542
Cloven has a spectacular aura about
Send a message via AIM to Cloven
Quote:
Originally Posted by Astram View Post
whats the +.5 for?
Because Graal's random functionality dislikes the high-end of a defined range for some reason. All values below the maximum value tend to have a higher probability of occurring.
Reply With Quote
  #6  
Old 03-02-2011, 08:00 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by DustyPorViva View Post
this.chat = int(random(0,100)+.5);

That does look cleaner, but I suggest getting as close to +1 as reasonably possible. with only +0.5, there's a ~0.5 out of 5 chance that it will actually roll he high number. Which is why you should, at the very least, tag +0.99 at the end. add more 9's the more important it is.
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #7  
Old 03-02-2011, 08:01 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Jiroxys7 View Post
That does look cleaner, but I suggest getting as close to +1 as reasonably possible. with only +0.5, there's a ~0.5 out of 5 chance that it will actually roll he high number. Which is why you should, at the very least, tag +0.99 at the end. add more 9's the more important it is.
You are reading it wrong. It generates a random number then adds .5 to it. With int() this effectively rounds the number up, eliminating the problem.
Reply With Quote
  #8  
Old 03-02-2011, 08:05 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by DustyPorViva View Post
You are reading it wrong. It generates a random number then adds .5 to it. With int() this effectively rounds the number up, eliminating the problem.
Ah, I see!
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.