Raised This Month: $ Target: $400
 0% 

Generate random string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FakeNick
Senior Member
Join Date: Feb 2008
Location: Poland
Old 07-27-2009 , 07:23   Generate random string
Reply With Quote #1

Hello.

Is there a way in PAWN to generate random string?
Thanks for code or an advice.

PS. Do not recommend me the RandomX module, i've tried that and it's not working.
__________________


[||||||||||] Snowball war v3.05

Pol
ish translations here ;) (PM me if you want one).


FakeNick is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 07-27-2009 , 07:33   Re: Generate random string
Reply With Quote #2

If you mean a string for a number, yes. On the other hand, generating a random string as in sentence, I'd need more explanation on what you're trying to do.
BOYSplayCS is offline
FakeNick
Senior Member
Join Date: Feb 2008
Location: Poland
Old 07-27-2009 , 07:42   Re: Generate random string
Reply With Quote #3

I'm trying to do a plugin to record demos on client side and i need a random name for that demo. F.e. something like that "ahagds.dem" or "ghjkqer.dem".
__________________


[||||||||||] Snowball war v3.05

Pol
ish translations here ;) (PM me if you want one).


FakeNick is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 07-27-2009 , 07:53   Re: Generate random string
Reply With Quote #4

PHP Code:
public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    new 
filename[11]
    
getRandomFilename(filename,6,"dem")
}

getRandomFilename(filename[],len,extension[])
{
    for(new 
i=0;i<len;i++)
    {
        
filename[i] = random_num('a','z')
    }
    
    
formatex(filename[len],4,".%s",extension)

If you want it to have numbers or other characters, tell me.
__________________
joaquimandrade is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 07-27-2009 , 07:59   Re: Generate random string
Reply With Quote #5

Pure randomness

PHP Code:
    for( new 0leni++ )
    {
        switch( 
)
        {
            case 
0filename] = random_num'0''9' );
            case 
1filename] = random_num'a''z' );
            case 
2filename] = random_num'A''Z' );
        }
    } 
__________________
xPaw is offline
FakeNick
Senior Member
Join Date: Feb 2008
Location: Poland
Old 07-27-2009 , 08:25   Re: Generate random string
Reply With Quote #6

Thanks xPaw and joaquimandrade .
+Karma of course.
__________________


[||||||||||] Snowball war v3.05

Pol
ish translations here ;) (PM me if you want one).


FakeNick is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 07-27-2009 , 08:26   Re: Generate random string
Reply With Quote #7

Quote:
Originally Posted by xPaw View Post
Pure randomness

PHP Code:
    for( new 0leni++ )
    {
        switch( 
)
        {
            case 
0filename] = random_num'0''9' );
            case 
1filename] = random_num'a''z' );
            case 
2filename] = random_num'A''Z' );
        }
    } 
LIES
BOYSplayCS is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 07-27-2009 , 08:32   Re: Generate random string
Reply With Quote #8

Yes lies. It's still pseudo-randomness
__________________
joaquimandrade is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 07-27-2009 , 10:30   Re: Generate random string
Reply With Quote #9

There's no use for the capital letters, when used for filenames they're the same.

It would also be more random if you used random_num(0,3) instead of i % 3
[ --<-@ ] Black Rose is offline
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 -4. The time now is 18:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode