SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 24/01/2011, 09:54 PM   #1
Davidovich
Little Clucker
 
Join Date: Jan 2011
Posts: 17
Reputation: 0
Default random number between two numbers

I've seen on wiki the random function but it only has the "max" parameter, so it would generate a number between 0 and "max-1".

how can I generate a random number between two numbers? Like 5 and 10.... it would generate 5, 6, 7, 8, 9 or 10.
Davidovich is offline  
Old 24/01/2011, 09:56 PM   #2
Fj0rtizFredde
Gangsta
 
Fj0rtizFredde's Avatar
 
Join Date: Jun 2008
Location: Sweden
Posts: 888
Reputation: 120
Default Re: random number between two numbers

Like this?
pawn Code:
stock randomEx(min, max)
{    
    //Credits to ******    
    new rand = random(max-min)+min;    
    return rand;
}
__________________
Latest crap I've made:
[Include]CleverBot - Never Be Alone Again!
Fj0rtizFredde is offline  
Old 24/01/2011, 09:59 PM   #3
Davidovich
Little Clucker
 
Join Date: Jan 2011
Posts: 17
Reputation: 0
Default Re: random number between two numbers

Quote:
Originally Posted by Fj0rtizFredde View Post
Like this?
pawn Code:
stock randomEx(min, max)
{    
    //Credits to ******    
    new rand = random(max-min)+min;    
    return rand;
}
hm
looks nice, lol, thanks
I would use like this?
Code:
new A = randomEx(5,10);
And, it would generate 5 and 10 or only 6, 7, 8 and 9?
Davidovich is offline  
Old 24/01/2011, 10:04 PM   #4
Fj0rtizFredde
Gangsta
 
Fj0rtizFredde's Avatar
 
Join Date: Jun 2008
Location: Sweden
Posts: 888
Reputation: 120
Default Re: random number between two numbers

Yes use it like that And Im not sure about if its 5-9 or 5-10 cant remember :/ Try it and you will find out
__________________
Latest crap I've made:
[Include]CleverBot - Never Be Alone Again!
Fj0rtizFredde is offline  
Old 24/01/2011, 10:06 PM   #5
Gabe
Big Clucker
 
Gabe's Avatar
 
Join Date: Jan 2011
Posts: 55
Reputation: 0
Default Re: random number between two numbers

It would generate 5-9
Gabe is offline  
Old 24/01/2011, 10:09 PM   #6
Davidovich
Little Clucker
 
Join Date: Jan 2011
Posts: 17
Reputation: 0
Default Re: random number between two numbers

ok thank you all
Davidovich is offline  
 

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
4digit random numbers THE_KNOWN Help Archive 7 18/01/2011 12:14 PM
[HELP] Random Numbers psoftware Help Archive 7 31/12/2010 06:14 PM
[Help] Random numbers Rainbow_Six Help Archive 4 21/10/2010 06:08 PM
[HELP] Random numbers? SiJ Help Archive 6 09/08/2009 02:14 PM
Need help with random numbers... *BueNoOo* Help Archive 11 18/06/2009 04:13 PM


All times are GMT. The time now is 05:37 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.