Skip to content

Instantly share code, notes, and snippets.

@logicrime
Created April 15, 2015 05:05
Show Gist options
  • Save logicrime/16cde1376489e2dd1711 to your computer and use it in GitHub Desktop.
Save logicrime/16cde1376489e2dd1711 to your computer and use it in GitHub Desktop.
junk.lua
#!/usr/bin/env lua
-- hayden jones
-- MIT/X11
-- junk.lua
-- just what it sounds like
junk = {}
function junk.randstream(str)
return coroutine.wrap(function ()
while true do
local mark = math.random(#str)
coroutine.yield(string.sub(str,mark,mark))
end
end)
end
-- for i in randstream("0123456789abcdef") do print(i) end
function junk.take(num, what)
local res = {}
for i=1,num do res[i] = what()
end
return res
end
function junk.table_to_string(t)
local res = ""
for i=1,#t do res = res..t[i] end
return res
end
--test = junk.take(16, junk.randstream("0123456789abcdef"))
--for k,v in pairs(test) do print(k,v) end
--print(junk.table_to_string(test))
return junk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment