SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 18/08/2011, 01:39 AM   #1
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,801
Reputation: 701
Default Random numeric strings

I need a way to generate random strings consisting of numeric characters only. I searched and went through over 10 pages but couldn't find anything. Can anyone assist me?
Scenario is offline  
Old 18/08/2011, 02:00 AM   #2
JaTochNietDan
High-roller
 
JaTochNietDan's Avatar
 
Join Date: Apr 2007
Location: Republic of Ireland
Posts: 2,502
Reputation: 363
Default Re: Random numeric strings

Couldn't you just use the random function a few times? If I read correctly all you want is a string of numbers right? If you don't care about the length you could just use something like random(500000); and if you do care about the length, just use random(9) a few times and then put them all in a string.
__________________
Releases:
[Includes]: [jBan] | [jBanLite]
[Plugins]: [FileManager] | [Execute]
[Applications]: [Remote Administrator *NEW] | [Script King] | [RCON GUI]
JaTochNietDan is offline  
Old 18/08/2011, 02:02 AM   #3
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,801
Reputation: 701
Default Re: Random numeric strings

Wouldn't that be inefficient?
Scenario is offline  
Old 18/08/2011, 02:09 AM   #4
=WoR=Varth
High-roller
 
=WoR=Varth's Avatar
 
Join Date: Apr 2011
Location: Indonesia
Posts: 1,988
Reputation: 133
Default Re: Random numeric strings

pawn Code:
format(string,sizeof(string),"%d",random(9999));
format(string,sizeof(string),"%d%d%d%d",random(9),random(9),random(9),random(9));
__________________
(RETIRED)
=WoR=Varth is offline  
Old 18/08/2011, 03:09 AM   #5
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,801
Reputation: 701
Default Re: Random numeric strings

Unless someone else responds with a better solution I can just use the code "varthshenon" provided. Thanks!
Scenario is offline  
Old 18/08/2011, 03:32 AM   #6
=WoR=Varth
High-roller
 
=WoR=Varth's Avatar
 
Join Date: Apr 2011
Location: Indonesia
Posts: 1,988
Reputation: 133
Default Re: Random numeric strings

Another.
pawn Code:
valstr(string,random(9999));
IDK which one is faster.
__________________
(RETIRED)
=WoR=Varth is offline  
Old 18/08/2011, 03:34 AM   #7
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,801
Reputation: 701
Default Re: Random numeric strings

Quote:
Originally Posted by varthshenon View Post
Another.
pawn Code:
valstr(string,random(9999));
IDK which one is faster.
I need the string to end up being 6 characters total. I'm just doing this:

pawn Code:
stock randNumber()
{
    new szString[13];
    format(szString, sizeof(szString), "%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9));
    return szString;
}
Scenario is offline  
Old 18/08/2011, 03:40 AM   #8
=WoR=Varth
High-roller
 
=WoR=Varth's Avatar
 
Join Date: Apr 2011
Location: Indonesia
Posts: 1,988
Reputation: 133
Default Re: Random numeric strings

Oh okay. Btw the length is 6, not 12.
__________________
(RETIRED)
=WoR=Varth is offline  
Old 18/08/2011, 03:44 AM   #9
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,801
Reputation: 701
Default Re: Random numeric strings

Quote:
Originally Posted by varthshenon View Post
Oh okay. Btw the length is 6, not 12.
I doubled it because I wasn't sure if each "%d" would count as two characters. I'll change it to 7.
Scenario is offline  
Old 18/08/2011, 03:45 AM   #10
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,199
Reputation: 229
Default Re: Random numeric strings

Why you use 9? isnt it 10?

0,1,2,3,4,5,6,7,8,9 = 10 not 9

Sorry if im wrong...
DRIFT_HUNTER 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
Check if numeric Anteino Help Archive 6 16/02/2011 07:57 PM
How to get the day as a non-numeric? Danny_Costelo Help Archive 25 17/05/2009 11:31 PM
Make string to numeric kevinsoftware Help Archive 5 05/04/2009 09:48 AM
[How To] Numeric command _System_ Help Archive 3 17/03/2009 01:57 PM
Check if is numeric TheAngel105 Help Archive 4 15/03/2009 07:50 AM


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


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