Remix.run Logo
quentinkent1 40 minutes ago

exactly. There is something wrong with the code snippet.

arpadav 18 minutes ago | parent | next [-]

No there is not. First element is defacto winner, but you still have to loop through the rest with 1/n chance of being selected to fully give each element a chance of winner selection

kleiba2 17 minutes ago | parent | prev [-]

On count == 1, the winner gets set to the first element, true. But the function does not return yet! So the value might get overwritten during the remainder of the for-loop.