-- PS, I Wi-Fi jump
I made a random string maker, but there's a flaw.
It can only put letters in order, how can I scramble them?
posted from my tablet, I don't have the code. I'm all not at home, so I can't get it.
Random strings
Started by Selys, Dec 27 2013 02:14 PM
6 replies to this topic
#1
Posted 27 December 2013 - 02:14 PM
#2
Posted 27 December 2013 - 02:28 PM
Please post the code.
#3
Posted 27 December 2013 - 02:33 PM
Well how are you creating the random strings?
Let's say that you have all the letters in a table then you could do this
Let's say that you have all the letters in a table then you could do this
local letters = {
"A", "B", "C",
}
local str = ""
for i = 1,5 do
str = str .. letters[math.random( 1, #letters )]
end
print(str)
#5
Posted 27 December 2013 - 03:28 PM
I saw that. You still need to post the code. You probably should have waited until you could post the code before asking. You can't apply the advice given until you have the code anyways.
You should probably take a single character from your set of characters for as many times as you want. Just getting a substring of the character set is why you're always getting them in that order.
You should probably take a single character from your set of characters for as many times as you want. Just getting a substring of the character set is why you're always getting them in that order.
#6
Posted 27 December 2013 - 05:55 PM
OK. Here's the code.
all = "1234567890ABCDEFGHIJKLMNZNOPZTUVQRSWXYZabcdefghjklnmoptuvqrswxys" e = "" local r1 = tonumber(math.random(1, 62)) local r2 = tonumber(math.random(r1, 62)) e = string.sub(r1, r2) print(e)
#7
Posted 27 December 2013 - 08:17 PM
I fixed your code tags. Use square brackets for code tags instead of angle brackets.
You should use math.random (which returns a number, no need for tonumber()) to determine the length of string you want, then use a loop that will pick a single character from the string and add it to the output string. Iterate the loop as many times as the number of characters long the string should be. You also forgot to specify all as the first argument of the string.sub up there.
You should use math.random (which returns a number, no need for tonumber()) to determine the length of string you want, then use a loop that will pick a single character from the string and add it to the output string. Iterate the loop as many times as the number of characters long the string should be. You also forgot to specify all as the first argument of the string.sub up there.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












