Most casual random pickers on the web suffer from hidden statistical biases — from using standard Math.random() with modulo arithmetic to flawed shuffling comparators. This guide breaks down the mathematics of hardware CSPRNG, rejection sampling, weighted probabilities, and derangements used in Calculover's Random Picker.

Why Math.random() and Modulo Arithmetic Skew Results

In JavaScript, Math.random() is not cryptographically secure and is not guaranteed by browser specifications to have uniform distribution across all operating systems. Worse, many online pickers take a random integer and use the modulo operator (randomUint % N). Because 232 (4,294,967,296) is rarely an exact multiple of the list size N, lower indices have a slightly higher probability of being chosen — an effect known as modulo bias.

Calculover uses the Web Crypto API (crypto.getRandomValues) to draw hardware-seeded 32-bit integers, combined with rejection sampling: any raw value falling within the incomplete remainder window [floor(2^32 / N) * N, 2^32) is discarded and redrawn. This guarantees mathematically exact, equiprobable selection for every candidate.

Weighted Raffle Probability and Sampling Without Replacement

In a weighted raffle, each entry i holds weight w_i. In a single draw, the probability of entry i winning is simply w_i / W_total. However, drawing multiple winners without replacement requires iterative sampling: once a candidate wins, their tickets are removed from the pool, the total weight reduces to W_total - w_winner, and the probabilities of all remaining candidates increase proportionally.

Calculover implements this exact roulette wheel reduction without replacement, ensuring that participants with multiple tickets receive their full mathematical advantage without allowing double wins.

Fisher–Yates Shuffling vs. Flawed Array Sorting

A common programming mistake is shuffling a list with array.sort(() => Math.random() - 0.5). This comparator violates transitivity (if A > B and B > C, A must be > C), producing a demonstrably skewed distribution where certain permutations are twice as likely as others.

Calculover uses the Durstenfeld implementation of the Fisher–Yates shuffle: iterating backward from index N-1 down to 1, swapping each element with an unbiased random element at or before its current index. This generates all N! permutations with equal 1 / N! probability.

Secret Santa and Derangement Mathematics

When organizing gift exchanges or peer reviews, a common pitfall is pairing someone with themselves. A valid Secret Santa assignment is a derangement — a permutation where no element is fixed (\pi(i) \ne i).

Calculover achieves this by generating an unbiased Hamiltonian cycle across the shuffled participants (Person 1 gives to Person 2, Person 2 gives to Person 3, ..., Person N gives to Person 1). This mathematical cycle guarantees zero self-giving and ensures a single continuous loop without isolated sub-groups.