Skip to main content

Selection functions

oneOf

Commentary

added in 0.0.5

Randomly selects a choice with equal probability.


Examples

Literal choices

{
"_gen": "oneOf",
"choices": [
"a",
"b",
"c"
]
}
[
"c",
"a",
"c",
"c",
"a"
]

Function choices

Each choice can be another generator.

{
"_gen": "oneOf",
"choices": [
{
"_gen": "string",
"expr": "#{Name.fullName}"
},
{
"_gen": "uniformDistribution",
"bounds": [
0,
5
]
},
{
"_gen": "boolean"
}
]
}
[
false,
3.0102549212577934,
4.322376493330335,
false,
false
]

Specification

JSON schema

{
"type": "object",
"properties": {
"choices": {
"oneOf": [
{
"type": "array",
"minItems": 1
},
{
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
}
]
}
},
"required": [
"choices"
]
}