ruby - Percentage is not working as expected -


i asked question on how insert item array based on objects percentage shown here. answer simple, yet tried it, set object, testsubject's percent 3, , ran using:

if rand(100) <= testsubject.percent     arr.push(testsubject.name) end 

but rand of 54 , percent of 3, works - shouldnt, always work, should only insert 3% of time, same with, if percent if 67, should insert 67% of time.

yet, seems to, states, if percentage less or equal testsubject.percent.

ideas?

how setting rand(100) rand_temp_variable, test variable <= testsubject.percent ? way debug / inspect value of rand_temp_variable , testsubject.percent see going on.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -