SA-MP Forums Archive
Random text string? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random text string? (/showthread.php?tid=276913)



Random text string? - linuxthefish - 15.08.2011

Hi, how can i generate a random text string from out of nowhere?

(I'm currently using exec plugin to execute the pwgen command to a file - then reading the file with fread.)


Re: Random text string? - WoodPecker - 15.08.2011

When you say out of nowhere , what you mean by saying this?


Re: Random text string? - linuxthefish - 15.08.2011

For example "Oochah9e" is a random string.


Re: Random text string? - WoodPecker - 15.08.2011

And why you want to use the random string or whatever you call it?


Re: Random text string? - RyDeR` - 15.08.2011

pawn Code:
stock randomString(strDest[], strLen = 10)
{
    while(strLen--)
        strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
}
Example:
pawn Code:
new
    string[10]
;
randomString(string, 10);



Re: Random text string? - linuxthefish - 15.08.2011

Quote:
Originally Posted by WoodPecker
View Post
And why you want to use the random string or whatever you call it?
I'm not discussing my project ideas.

Quote:
Originally Posted by RyDeR`
View Post
pawn Code:
stock randomString(strDest[], strLen = 10)
{
    while(strLen--)
        strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
}
Example:
pawn Code:
new
    string[10]
;
randomString(string, 10);
Thanks, that's just what i was looking for!

ffs, "You have given out too much Reputation in the last 24 hours, try again later."


Re: Random text string? - Scenario - 15.08.2011

Quote:
Originally Posted by linuxthefish
View Post
I'm not discussing my project ideas.



Thanks, that's just what i was looking for!

ffs, "You have given out too much Reputation in the last 24 hours, try again later."
I gave him some reputation for you.


Re: Random text string? - Jefff - 15.08.2011

Quote:
Originally Posted by RyDeR`
View Post
pawn Code:
stock randomString(strDest[], strLen = 10)
{
    while(strLen--)
        strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
}
Example:
pawn Code:
new
    string[10]
;
randomString(string, 10);
string[9] = random(bla bla) = crash, must be +1

pawn Code:
new
    string[11]
;
:> string[10] = EOS


Re: Random text string? - RyDeR` - 15.08.2011

Quote:
Originally Posted by Jefff
View Post
string[9] = random(bla bla) = crash, must be +1

pawn Code:
new
    string[11]
;
:> string[10] = EOS
No, you're wrong - we first subtract than assign so it will always have 1 less. If you print this:
pawn Code:
while(strLen--) // strLen is assigned to 10
    printf("%d", strLen);
Then you'll see that this will give
Code:
9
8
7
6
5
4
3
2
1
0
which is actually safe.


Re: Random text string? - MadeMan - 16.08.2011

Quote:
Originally Posted by RyDeR`
View Post
No, you're wrong - we first subtract than assign so it will always have 1 less. If you print this:
pawn Code:
while(strLen--) // strLen is assigned to 10
    printf("%d", strLen);
Then you'll see that this will give
Code:
9
8
7
6
5
4
3
2
1
0
which is actually safe.
But string[9] should be 0