Random text string?
#1

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.)
Reply
#2

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

For example "Oochah9e" is a random string.
Reply
#4

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

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);
Reply
#6

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."
Reply
#7

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.
Reply
#8

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
Reply
#9

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.
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)