Random AlphaNumeric String Generator

OK, because I always hack on servers. I use this snippet to change my name into a random/obfuscated string before I log out so that I will not get caught by admins.It is an awesome snippet for me.

Idea:
It can be integrated on cleo scripts that changes the player name everytime he joins a server... Interesting.

Code:
    {
    Usage:
    0AC8: 0@ = allocate_memory_size 21
    0AB1: call_scm_func @randomnamegenerator 2 _inoutname 0@ _charcount 20
    0AD1: show_formatted_text_highpriority "%s" time 2000 0@
    0AC9: free_allocated_memory 0@
    
    NOTICE:
    - THE ALLOCATED MEMORY MUST BE GREATER THAN THE CHARACTER COUNT! As you can see on the example usage the allocated is 21 and the charcount is 20, you can set more than 21 allocated memory BUT NOT BELOW OR EQUAL TO 20 in the example
    }
:randomnamegenerator

// ~~~~~~~~~~~~~~~First CHaracter is always an alphacharacter
while true // make sure to generate alpha character
    0209: 29@ = random_int_in_ranges 65 123 // alphacharacter
    if or
        29@ <= 90 // end of uppercase
        29@ >= 97 // start of lowercase
    then break
    end
end
0A8C: write_memory 0@ size 1 value 29@ virtual_protect 1
0@++ // step 1 byte
// ~~~~~~~~~~~~~~~

for 31@ = 2 to 1@  // charcount down to 2nd byte
    while true // make sure to generate alpha character
        0209: 29@ = random_int_in_ranges 48 123 // alphanumericcharacter
        if 29@ <= 57 // is a numeric ascii character
        then break
        else
            if and
                29@ >= 65 // start of uppercase
                29@ <= 90 // end of uppercase
            then break
            else
                if and
                    29@ >= 97 // start of lowercase
                    29@ <= 122 // end of lowercase
                then break
                end
            end
        end
    end
    0A8C: write_memory 0@ size 1 value 29@ virtual_protect 1
    0@++ // step 1 byte
end

0A8C: write_memory 0@ size 1 value 0x0 virtual_protect 1 // null terminator at the end of the string

ret 0
 
Top