Excluding capital Is and lower Ls from a string
#1

Hi,
I'm using Ryder's random string generator and there's a slight confusion when it adds up a capital I or a lower L so I tried adjusting it in order to exclude these from the string but it didn't work:
Код:
stock randomString(strDest[], strLen = 11)
{
	new letter[1];
	while(strLen--)
	{
		letter[0] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
		while(!strcmp(letter[0], "I", false) || !strcmp(letter[0], "l", false))
		{
			letter[0] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
		}
		strDest[strLen] = letter[0];
	}
}
What could be the problem? Thanks.
Reply
#2

*deleted*
Reply
#3

PHP код:
stock randomString(strDest[], strLen 11)
{
    new 
letter;
    while(
strLen--)
    {
        
letter random(2) ? (random(25) + (random(2) ? 'a' 'A')) : (random(10) + '0');
        if (
letter == 'I')
            
letter 'Z';
        else if (
letter == 'l')
            
letter 'z';
        
strDest[strLen] = letter;
    }

Generates less letters and swaps some.
Reply
#4

Why do you use strcmp for comparing one letter?

Just do

Код:
if(letter[0] == 'I' || letter[0] == 'l')
You could also use a do while loop instead of using the same instruction twice:

Код:
do
{
letter[0] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
} while(letter[0] == 'I' || letter[0] == 'l');
Other than that it should work.

EDIT: Oops too late.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)