AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Generate random string (https://forums.alliedmods.net/showthread.php?t=98612)

FakeNick 07-27-2009 07:23

Generate random string
 
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.

BOYSplayCS 07-27-2009 07:33

Re: Generate random string
 
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.

FakeNick 07-27-2009 07:42

Re: Generate random string
 
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".

joaquimandrade 07-27-2009 07:53

Re: Generate random string
 
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.

xPaw 07-27-2009 07:59

Re: Generate random string
 
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' );
        }
    } 


FakeNick 07-27-2009 08:25

Re: Generate random string
 
Thanks xPaw and joaquimandrade :).
+Karma of course.

BOYSplayCS 07-27-2009 08:26

Re: Generate random string
 
Quote:

Originally Posted by xPaw (Post 882913)
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

joaquimandrade 07-27-2009 08:32

Re: Generate random string
 
Yes lies. It's still pseudo-randomness

[ --<-@ ] Black Rose 07-27-2009 10:30

Re: Generate random string
 
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


All times are GMT -4. The time now is 18:26.

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