Draw an unbiased ticket index from ICP raw randomness
A uniformly random byte does not divide evenly into six outcomes. A canister can reject the unused tail before converting randomness into a ticket number.
Count the possible inputs
The management canister's raw_rand supplies random bytes asynchronously. For six tickets, the values from 0 through 251 contain exactly 42 complete groups of six. Reject 252 through 255 and try the next byte. If the buffer runs out, obtain more randomness without changing the ticket list.
ticket_count = 6
accept a byte below 252
winner_index = accepted_byte % 6
Freeze entries before awaiting randomness
Persist the ordered entries and draw identifier before the asynchronous request. Prevent a second caller from reopening the draw after an unfavorable result. Rejection sampling addresses numerical bias only. Selection also depends on who controls entries, ordering and the ability to rerun a draw.