Jump to content

Letras aleatórias


Recommended Posts

function generateString ( len )
    
    if tonumber ( len ) then
        math.randomseed ( getTickCount () )

        local str = ""
        for i = 1, len do
            local charlist = allowed[math.random ( 1, 3 )]
            str = str .. string.char ( math.random ( charlist[1], charlist[2] ) )
        end

        return str
    end
    
    return false
    
end
  
function randomnum 
    outputChatBox ( "Generated string was: " .. generateString ( 8 ), root, 0, 255, 0 )
end 
  
addCommandHandler ( "callrandom", randomnum ) 

Server-side, não funcionou

Link to comment
  • Other Languages Moderators

Vc esqueceu de copiar uma parte do código-fonte lá da Wiki. Vc precisa copiar tudo que está dentro do retângulo azul.

Source Code

local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } -- numbers/lowercase chars/uppercase chars

function generateString ( len )
    
    if tonumber ( len ) then
        math.randomseed ( getTickCount () )

        local str = ""
        for i = 1, len do
            local charlist = allowed[math.random ( 1, 3 )]
            str = str .. string.char ( math.random ( charlist[1], charlist[2] ) )
        end

        return str
    end
    
    return false
    
end
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...