Weighted random · Custom probability · Lottery weights · Free
Weighted Random Picker — Assign Probability to Each Item
Open Weighted Random Picker →Standard random selection gives every item an equal chance. But many real-world situations require weighted random selection, where some items are more likely to be picked than others. A participant who bought five raffle tickets should have five times the chance of winning compared to someone who bought one. A test variant that is being cautiously rolled out might receive only 10% of traffic. A customer tier with higher spend might earn priority in a prize draw.
The Flowfiles Random Line Picker supports weighted random selection natively. Check the "Weighted" option and use a simple pipe syntax to assign each item a numeric weight. The draw then respects these weights exactly, with each item's selection probability proportional to its weight relative to the total.
How Weighted Random Works
In a weighted draw, the probability of selecting an item is its weight divided by the sum of all weights. If you have three items with weights 1, 2, and 3, the total is 6, so the probabilities are 1/6 ≈ 16.7%, 2/6 ≈ 33.3%, and 3/6 = 50%. The tool implements this with the linear scan method: it generates a random number between 0 and the total weight, then walks through the items subtracting each weight until the running total becomes zero or negative. The item that causes the total to reach zero is the selected one.
This method is O(n) and perfectly uniform in terms of probability distribution, making it the standard approach for weighted random sampling in browser-side JavaScript.
Syntax for Weighted Items
Add a pipe character | followed by a positive number at the end of each line. The number is the weight. Items without a weight suffix are automatically assigned weight 1.
In this example, Alice has weight 3, Bob has weight 1, Carol has weight 2, and Dave has weight 1 (default). The total is 7. Alice's probability is 3/7 ≈ 42.9%, Carol's is 2/7 ≈ 28.6%, and both Bob and Dave have 1/7 ≈ 14.3%.
Decimal weights are also supported, which is useful when working with percentages:
Use Cases for Weighted Random
- Raffle with multiple tickets — Each participant is entered once per ticket purchased. Instead of entering their name multiple times, add their name with a weight equal to the number of tickets.
- A/B/C traffic splitting — When manually simulating a traffic split or deciding which variant to present in a manual test, use weighted picks to match your target percentages.
- Priority queues — Items or people with higher priority get a higher weight, increasing their chance of being selected without making it a certainty.
- Loot tables in game design — Assign rare items low weights and common items high weights to simulate loot drops without writing code.
- Survey sampling — When a population has subgroups of different sizes and you want proportional representation in your sample, weight each subgroup by its relative size.
- Gamified incentive systems — Employees who completed more challenges get more "entries" into a prize draw, represented by a higher weight in the list.
Weighted Draw Without Replacement
When drawing multiple items from a weighted list without replacement, the tool removes each picked item from the pool before the next draw. This means weights are renormalized at each step: after Alice is picked, the remaining pool contains only Bob, Carol, and Dave with their original weights, and the new probabilities are computed from the reduced total. This is the correct behavior for sequential weighted draws, equivalent to dealing hands from a stacked deck without putting cards back.
Calculating Expected Pick Frequency
If you want to verify your weights produce the intended distribution, run a batch of picks. Switch to Multiple picks mode, set the count to 100 or 1000, enable "No duplicates" only if needed (disable it for frequency testing with replacement), and export the results as CSV. Count the occurrences of each item — they should roughly match the theoretical probabilities.
Frequently Asked Questions
Can I use fractional weights like 0.5?
Yes. The tool accepts any positive number, including decimals. The ratio between weights is what matters, not their absolute values.
What happens to items without a weight?
Items without the pipe-weight suffix are automatically assigned a weight of 1, making them part of the pool with base probability.
Is there a maximum weight value?
No. However, extremely large weights relative to others will make the high-weight item almost certain to be selected. Balance your weights to reflect the intended probabilities.
Can I mix weighted and unweighted items in the same list?
Yes. Items without a weight suffix default to 1. You can freely mix explicit and implicit weights in the same list.