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

Popular posts from this blog

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

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -