Last active
December 25, 2015 12:59
-
-
Save error454/6979894 to your computer and use it in GitHub Desktop.
Random number test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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