Selection functions
weightedOneOf
Commentary
added in 0.0.5
Randomly selects a choice using the supplied probabilities.
Examples
Choosing a value
{
"_gen": "weightedOneOf",
"choices": [
{
"weight": 4,
"value": "hello"
},
{
"weight": 6,
"value": "world"
}
]
}
[
"hello",
"world",
"world",
"world",
"hello"
]
Specification
JSON schema
{
"type": "object",
"properties": {
"choices": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"weight": {
"type": "number",
"minimum": 0
}
},
"required": [
"weight",
"value"
]
}
}
},
"required": [
"choices"
]
}