Skip to content

Instantly share code, notes, and snippets.

@error454
Last active December 25, 2015 12:59
Show Gist options
  • Select an option

  • Save error454/6979894 to your computer and use it in GitHub Desktop.

Select an option

Save error454/6979894 to your computer and use it in GitHub Desktop.
Random number test
function Misc.debugRandomUnitTest ( min, max )
local count = 10000
local tTest = table.newInstance ( )
table.reserve ( tTest, count )
local t_add = table.add
local rand = math.random
local round = math.roundToNearestInteger
for i = 0, count do
t_add(tTest, round ( rand ( min, max) ))
end
-- count them
local zeros = 0
local ones = 1
for i = 0, table.getSize ( tTest ) - 1 do
local v = table.getAt ( tTest, i )
if(v == 0) then
zeros = zeros + 1
else
ones = ones + 1
end
end
log.message ( "Zeros: " .. zeros/count * 100 )
log.message ( "Ones: " .. ones/count * 100 )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment