0

I want to randomly select an item from a list with some sort of preference that will increase the probability of some items to be picked over others in Java. I have done the normal random selection but now I want to include this. I was thinking of increasing the number of a particular item, like duplicating it multiple times in the list, but I don't feel it's the right way to go.

My other idea might involve a 2 dimensional array, so maybe apples will have an integer point of 6, then orange will have a point of 3. This way apples will have more preference than orange. I'm just suggesting, I don't even know how to use multidimensional arrays.

Any ideas are welcome.

Roach
  • 610
  • 1
  • 8
  • 13
  • Please specify more details about "preference". Some code would be useful. – Valentino Nov 06 '16 at 05:27
  • @Valentino I have edited to add a simple concept. I didn't say I have coded it, so I don't have any code to paste – Roach Nov 06 '16 at 05:56
  • You must give a mathematical description of the relation between "preference" and "probability" if you want help on coding. Only you can specify the requirements of your problem. One example would be: probability is directly proportional to preference value. Another one longer example: all preference value less than 3 have probability 0.3; those between 3 and 7 will have 0.3 and those greater than 7 will have 0.4. – Valentino Nov 06 '16 at 06:35
  • @Valentino that is basically what I have put in the edit with the apples and oranges – Roach Nov 06 '16 at 07:36

1 Answers1

0

Assuming the by preference you mean setting some itmes to get selected more number of times in several runs.

lets say you have items 0,1,2,3,4,5,6,7,8,9

do grouping like

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 the random group (1,2,3) then select the item in the group.

as you see high preference 0,1,2,3 has more chances then medium and low.

Sush
  • 3,864
  • 2
  • 17
  • 35
  • Okay, but with this, will those with low preference ever be selected? I want them to be selected also, sometimes – Roach Nov 06 '16 at 05:46
  • yeah.. if u select the group 1, then low preferences has chnace to get selected.. its jst matter of how many groups,how many items in groups and more important which items in the those group. – Sush Nov 06 '16 at 05:49
  • so with this, I will have to select from different groups depending on the preference level I want, like I'll select from group 2 if I want medium preference? I'm just trying to understand your algorithm. If it's this way, it really won't be great because what I need is something that picks from one single group of items. – Roach Nov 06 '16 at 05:55
  • this will simple one were you have to select two times ramdom selection. else you have to go for multiple random slection techniques.. where higher preference items shold get selected less number to qualify the selection where less preference sholud get more number of times. Again it will include more runs. – Sush Nov 06 '16 at 10:42