Skip to content

Instantly share code, notes, and snippets.

@silentbicycle
Created July 25, 2012 15:10
Show Gist options
  • Save silentbicycle/3176678 to your computer and use it in GitHub Desktop.
Save silentbicycle/3176678 to your computer and use it in GitHub Desktop.
Generate appropriate input for testing run-length encoding
-- Generate a random array of bytes, with some redundancy (via sorting).
function gen_int_array(limit)
limit = limit or 10000
local ri = lunatest.random_int
local length = ri(1, limit)
local ints = {}
for i=1,length do
-- keep them small, to increase duplication
ints[i] = ri(0, 2^8 - 1)
end
-- group repeated values together
table.sort(ints)
return ints
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment