generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: reliable function that returns a random sequence of letters

Previous Thread :: Next Thread 
Emess is not online. Emess
Joined: 01 Apr 2010
Total Posts: 13331
13 Aug 2011 03:14 PM
function getRandomSequenceOfLetters()
    return "sdfgw"
end
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
13 Aug 2011 03:14 PM
:O HAX
Report Abuse
blocco is not online. 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
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
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 is not online. 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 is not online. 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
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
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 is not online. Razer100
Joined: 28 Aug 2009
Total Posts: 8066
13 Aug 2011 04:09 PM
EWWW

-Foster The People- ~ma quỷ
Report Abuse
popinman322 is not online. popinman322
Joined: 04 Mar 2009
Total Posts: 5184
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image