Emess
|
  |
| Joined: 01 Apr 2010 |
| Total Posts: 13331 |
|
|
| 13 Aug 2011 03:14 PM |
function getRandomSequenceOfLetters() return "sdfgw" end |
|
|
| Report Abuse |
|
|
| |
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 13 Aug 2011 03:14 PM |
| It's not random. The "w" was added in for effect. |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 03:22 PM |
math.randomseed(os.time())
local function GenerateString(Length, AllowedChars) -- AllowedChars can be a table or a string. If it is a string, all characters in that string will be allowed. If it is a table, every string in the table will be allowed. Length = type(Length) == "number" and Length or 100 AllowedChars = (type(AllowedChars) == "table" or type(AllowedChars) == "string") and AllowedChars or "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
if type(AllowedChars) == "string" then local Allowed = {} for i = 1, #AllowedChars do Allowed[#Allowed+1] = AllowedChars:sub(i, i) end AllowedChars = Allowed end
local String = ""
for i = 1, Length do String = String .. AllowedChars[math.random(1, #AllowedChars)] end
return String end
print(GenerateString())
|
|
|
| Report Abuse |
|
|
aboy5643a
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2785 |
|
|
| 13 Aug 2011 03:23 PM |
>sgwdf
~Post here if you're Viet Namese, Canadian or Chinese. I'm from these 3 places. - Some confused kid from Language Center ~ |
|
|
| Report Abuse |
|
|
aboy5643a
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2785 |
|
|
| 13 Aug 2011 03:25 PM |
It did it wrong D: Forgot to include that... waiting... waiting... waiting... waiting...
~Post here if you're Viet Namese, Canadian or Chinese. I'm from these 3 places. - Some confused kid from Language Center ~ |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 04:08 PM |
Made a small Lua script that runs a nice program. Lolz. There is a problem, but I'm too lazy to fix it.
This will only run properly using the standalone official Lua VM.
local PrintGenerations = false -- Whether it prints every generation tried or not. print [[ This script will constantly generate strings of the same length as the string you chosen and using the same characters. It will print how much generations it needed to generate your string. It will then wait half a second and start again.
Printing in a file will NOT work. ]]
io.write "String: " local StringWanted = io.read() io.write "Print Generations (Y/N)?: " local PrintGenerations = io.read():lower() == "y" io.write "Output results in a file (Y/N)?:\t(This doesn't work currently)" local OutputResults = io.read():lower() == "y"
if OutputResults then Output = io.open("Results.txt", 'w+') end
local Len = #StringWanted
local function wait(t) local StartTime = os.time() t = t or 0 local EndTime = StartTime + t while os.time() < EndTime do end return os.time() - StartTime end
math.randomseed(os.time())
local function GenerateString(Length, AllowedChars) -- AllowedChars can be a table or a string. If it is a string, all characters in that string will be allowed. If it is a table, every string in the table will be allowed. Length = type(Length) == "number" and Length or 100 AllowedChars = (type(AllowedChars) == "table" or type(AllowedChars) == "string") and AllowedChars or "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
if type(AllowedChars) == "string" then local Allowed = {} for i = 1, #AllowedChars do Allowed[#Allowed+1] = AllowedChars:sub(i, i) end AllowedChars = Allowed end
local String = ""
for i = 1, Length do String = String .. AllowedChars[math.random(1, #AllowedChars)] end
return String end
while wait(.5) do for i = 1, math.huge do local S = GenerateString(Len, StringWanted) if PrintGenerations then print(S) end if S == StringWanted then if OutputResults then Output:write("String generated in " .. i .. " generations.") end print("String generated in " .. i .. " generations.") break end end end
|
|
|
| Report Abuse |
|
|
Razer100
|
  |
| Joined: 28 Aug 2009 |
| Total Posts: 8066 |
|
|
| 13 Aug 2011 04:09 PM |
EWWW
-Foster The People- ~ma quỷ |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2011 04:14 PM |
local letters = {} for i=string.byte('a'), string.byte('z') do table.insert(letters, string.char(i)) end
function getRandomString(length) length = tonumber(length) or 0 if length <= 0 then return end local ReturnString = "" for i=1, length do ReturnString = table.concat{ReturnString, ("")[math.random(0,1) == 1 and "upper" or "lower"](letters[math.random(1,#letters)])} end return ReturnString end |
|
|
| Report Abuse |
|
|