So i have this weight problem…

At least, that’s how I call it. Let me go into details.

I have 5 jars, and each jar has a unique flavor that I want to taste. The jars are labeled from A to E.

What i’m doing at the moment: randomly picking a jar and displaying it. Only that randomly picking the jar is… random… and that means that I have a pretty big chance of getting the same jar two or three times while not getting another jar that may have not been opened.

Now, the jars have different flavors inside. If I like the taste, I should have a bigger chance of getting that jar, while if I didn’t like the taste, i should have a really small chance of getting it again.

How can I do this?

I was thinking about a weight problem.

Let’s say that each jar has a ‘weight’ of 1000mg. If I have 5 jars, the weight of them will be 5000mg.

Jar Jar weight Total weight Probability
A 1000mg 1000mg 20%
B 1000mg 2000mg 20%
C 1000mg 3000mg 20%
D 1000mg 4000mg 20%
E 1000mg 5000mg 20%

Now I can do a random of 1000*N (N = number of jars). If i’ll get number 3302, I’ll taste jar D. If I get 4232 I’ll taste jar E and so on.

Now, i was thinking, if I pick jar D and I like it thus I want to have a bigger chance of getting it, I should increase it’s weight. To remain in the same total sum, I should substract from the other jars weight. Let’s say I’ll add 200mg if I like it and subtract 400mg if I don’t.

I pick jar D, i like it, I increase it’s weight to 1200. Those 200mg have to be taken from the other 4 jars. Thus i’ll have:

Jar Jar weight Total weight Probability
A 950mg 950mg 19%
B 950mg 1900mg 19%
C 950mg 2850mg 19%
D 1200mg 4050mg 24%
E 950mg 5000mg 19%

Now, because jar D occupies a larger space in the weight system, it has a bigger chance of being picked.

I take jar E, i don’t like it, so i substract from it 400mg and give to the others.

Jar Jar weight Total weight Probability
A 1050mg 1050mg 21%
B 1050mg 2100mg 21%
C 1050mg 3150mg 21%
D 1300mg 4350mg 26%
E 550mg 5000mg 11%

Let’s say, I took another taste of D, but now i don’t like it so I adjust the weight

Jar Jar weight Total weight Probability
A 1150mg 1150mg 23%
B 1150mg 2200mg 23%
C 1150mg 3450mg 23%
D 900mg 4350mg 18%
E 650mg 5000mg 13%

As you can see, the algorithm is very punishing if I don’t like the flavor and advantages the chance of me picking something that I either like or that I haven’t tried yet.


Do you have anything to add? Would you see another algorithm that can work better and achieve the same results?

Leave a Comment


Recent posts

Privacy Preference Center