Ruby - insert into an array based on a percentage -
i have object called testsubject
can use access following data, name
, percent
want insert name based on percent, array. example,
arr.push(testsubject.name)
based on percentage of testsubject, in case puts testsubject.percent #=> 90
this means specific name has 90% chance of being pushed array. how ever not sure how write in ruby syntax.
any ideas?
arr.push(testsubject.name) if rand(100) <= testsubject.percent
Comments
Post a Comment