Weighted Random Item Picker
Actualweightedcategoricaldrawoneadvancingsource,weightsnonnegativefinitepositive sum,zeroweightpositionsneverselected. Candidatepositionsnotnecessarilydistinctvalues;not secure randomness.
Description
Weighted selection gives each candidate position a probability proportional to its nonnegative weight.
Weighted selection gives each candidate position a probability proportional to its nonnegative weight.1
Duplicate candidate labels can occupy separate weighted positions, while zero-weight positions are skipped.
When to use Weighted Random Item Picker
Use this tool to apply the stated weighted random item picker operation with an explicit input and unit basis.
How to use Weighted Random Item Picker and how it works
- Establish the text or game convention described above.
- Enter seed, actualCandidateValues, callerActualNonnegativeWeights and run the tool.
- Read result.selectedValue using the output meanings below.
- If input is rejected, correct the stated type, range, ordering or alignment issue and rerun; review successful results under the declared convention.
| Input field | Meaning | Value type | Requirement |
|---|---|---|---|
| seed | Nonblank reproducibility string, at most 256 characters; required even with a supplied random source. | string | required; further conditions in the algorithm |
| actualCandidateValues | Candidate values, on the basis specified in the algorithm. | array of string | required; dense; align related rows as specified; at most 128 strings; 128 UTF-16 units each; further conditions in the algorithm |
| callerActualNonnegativeWeights | Nonnegative weights, on the basis specified in the algorithm. | array of number | required; dense; align related rows as specified; further conditions in the algorithm |
Require aligned nonempty arrays and positive total weight. Draw x in [0,total), then select the first cumulative weight exceeding x; use the final positive-weight position as a rounding fallback. A nonblank seed of at most 256 characters selects the existing seeded generator unless execution context supplies random. One source advances through the request; supplied samples must be finite in [0,1). These draws are not cryptographically secure.
The default source hashes the seed’s UTF-16 units into an integer state and advances a deterministic arithmetic generator for each sample. A supplied execution-context random source takes precedence; it must return finite values in [0,1). The required seed still must be nonblank and at most 256 characters. These draws are reproducible entertainment or sampling, without cryptographic unpredictability.2
position probability = weightᵢ / Σweights Apply the declared units, ordering and branch conditions.
| Output field | Meaning | Value type |
|---|---|---|
| result | Object containing the declared output fields. | object |
| result.selectedValue | One selected candidate label; repeated labels may occupy multiple positions. | string |
{
"input": {
"seed": "batch51",
"actualCandidateValues": [
"a",
"b"
],
"callerActualNonnegativeWeights": [
1,
3
]
},
"output": {
"result": {
"selectedValue": "b"
}
}
} Limitations and assumptions
The output applies the declared operation to the values you supply. Establish the measurement basis, units, coefficients and any caller-selected rules before interpreting it. The tool does not independently collect or verify observations or decide whether a model or reference applies.
Supply explicit required fields with the documented types and dense aligned arrays. Unknown fields, wrong types and nonfinite numbers are rejected. Branch-specific constraints are explained above. A successful false boolean, negative signed difference, empty slice or unresolved tie is distinct from an input error. Very large inputs or outputs may be rejected by shared resource limits.
Alternative or Complementary methods
For a related operation, use Subset Checker. Set inclusion asks whether every distinct candidate value appears in a supplied superset.
For a related operation, use List Slice Tool. A list slice selects a span using zero-based indices and an exclusive end.
References
-
Weighted Random Item Picker — tool.io
-
Existing seeded random generator — tool.io
Similar or alternative tools
- Subset Checker
Set inclusion asks whether every distinct candidate value appears in a supplied superset.
- List Slice Tool
A list slice selects a span using zero-based indices and an exclusive end.