Skip to main content

Function modifiers

sample

Commentary

added in 1.5.6

Randomly selects a subset of elements from an array.


Examples

Static rate

Set sample / rate to a decimal between 0 and 1, representing the percentage of elements from the array to retain.

{
"_gen": "repeatedly",
"n": 5,
"target": {
"_gen": "oneOf",
"choices": [
"A",
"B",
"C",
"D",
"E",
"F"
]
},
"sample": {
"rate": 0.5
}
}
[
[
"B",
"A"
],
[
"D",
"D",
"E"
],
[
"B",
"A",
"B",
"F"
],
[
"C",
"E"
],
[
"D"
]
]

Dynamic rate

rate can also be a set to a function.

{
"_gen": "repeatedly",
"n": 5,
"target": {
"_gen": "oneOf",
"choices": [
"A",
"B",
"C",
"D",
"E",
"F"
]
},
"sample": {
"rate": {
"_gen": "uniformDistribution",
"bounds": [
0.2,
0.8
]
}
}
}
[
[
"A"
],
[
"B",
"B"
],
[
"C",
"C"
],
[
"A",
"C",
"A"
],
[
"D",
"B",
"D"
],
[
"C",
"F"
],
[
"C",
"C",
"B",
"C"
],
[
"D",
"A",
"C"
]
]

Specification

JSON schema

{
"type": "object",
"properties": {
"sample": {
"type": "object",
"properties": {
"rate": {
"oneOf": [
{
"type": "number",
"minimum": 0,
"maximum": 1
},
{
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
}
]
}
},
"required": [
"rate"
]
}
}
}