ODutii Posted November 16, 2019 Share Posted November 16, 2019 Eu sei deixar sortear números aleatórios, mais não sei com letras, alguem pode me mandar um math.random com letras do alfabeto? Link to comment
Other Languages Moderators Lord Henry Posted November 16, 2019 Other Languages Moderators Share Posted November 16, 2019 Use a função útil: GenerateString Link to comment
ODutii Posted November 16, 2019 Author Share Posted November 16, 2019 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 Lord Henry Posted November 16, 2019 Other Languages Moderators Share Posted November 16, 2019 (edited) Falta o parênteses dos parâmetros na sua função. Preste mais atenção. Edited November 16, 2019 by Lord Henry Link to comment
ODutii Posted November 16, 2019 Author Share Posted November 16, 2019 Ah, desculpe, eu tinha colocado no script so que aqui foi sem, mais ta dando problema na linha 8, allowed, (a nil value) Link to comment
Other Languages Moderators Lord Henry Posted November 17, 2019 Other Languages Moderators Share Posted November 17, 2019 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now