ORETD-278
function getRandomLetter() -- This function will return a random letter from the alphabet
local alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "w", "x", "y", "z"}
return alphabet[math.random(#alphabet)] -- math.random will return a random number from 1 to 25, as #alphabet is 25. This is then used to index into the alphabet array
end --
function getRandomNumber() -- This function will return a random number between 1 and 9
local numbers = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
return numbers[math.random(#numbers)] -- math.random will return a random number from 1 to 9, as #numbers is 9. This is then used to index into the numbers array
end --
function getRandomPassword() -- This function will return a random password which consists of 3 letters, 3 numbers and 2 letters
local password = ""
for i = 1, 3 do
password = password .. getRandomLetter()
end --
for i = 1, 3 do
password = password .. getRandomNumber()
end --
for i = 1, 2 do
password = password .. getRandomLetter()
end --
return password
end --
```
print(getRandomPassword()) -- This will print a random password to the console, for instance "r8a557ft"
2018年6月15日