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"
]
}
[
"a",
"b",
"b",
"a",
"c"
]

Function choices

Each choice can be another generator.

{
"_gen": "oneOf",
"choices": [
{
"_gen": "string",
"expr": "#{Name.fullName}"
},
{
"_gen": "uniformDistribution",
"bounds": [
0,
5
]
},
{
"_gen": "boolean"
}
]
}
[
false,
2.225682982542801,
"Tracy Langworth PhD",
3.6114853445792416,
"Robby Osinski I"
]

Specification

JSON schema

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