java - How to get a random item from a list with some preference -
this question has answer here:
- random weighted selection in java 6 answers
i want randomly select item list sort of preference increase probability of items picked on others in java. have done normal random selection want include this. thinking of increasing number of particular item, duplicating multiple times in list, don't feel it's right way go.
my other idea might involve 2 dimensional array, maybe apples have integer point of 6, orange have point of 3. way apples have more preference orange. i'm suggesting, don't know how use multidimensional arrays.
any ideas welcome.
assuming preference mean setting itmes selected more number of times in several runs.
lets have items 0,1,2,3,4,5,6,7,8,9
do grouping
group 1(preference 2 - low preference) 0,1,2,3,4,5,6,7,8,9
group 2(preference 1 - medium preference) 0,1,2,3,4,5,6
group 3(preference 0 - high preference) 0,1,2,3
now first select random group (1,2,3) select item in group.
as see high preference 0,1,2,3 has more chances medium , low.
Comments
Post a Comment