| ▲ | dsego an hour ago | |||||||||||||
Why doesn't it return on the first match? | ||||||||||||||
| ▲ | yoz-y 40 minutes ago | parent | next [-] | |||||||||||||
Because it would always return the first match in that case. You still need to see all of the items once. Imagine you have 2 items. First one has 100% chance to be selected. So it does. Then the second has 50% chance to be selected. If it isn’t you effectively chosen the first one and have 50/50 chance to return either. Now you add a third item. There is 50/50 chance of having either selected. And 1/3 chance of replacing the selection with the new one. Resulting in a 1/3 chance of selecting any of the three. (Because 1/2-1/6 = 1/3) 1/6 because there is 50% chance you will “steal” the selection. | ||||||||||||||
| ||||||||||||||
| ▲ | quentinkent1 42 minutes ago | parent | prev [-] | |||||||||||||
exactly. There is something wrong with the code snippet. | ||||||||||||||
| ||||||||||||||