Skip to main content

Transformation functions

repeatedly

Commentary

added in 0.0.18

Generates an array of n elements of target.

By default, all elements generated by repeatedly will reference the same values in vars on each iteration. But if you set iterateVars to an array of variable names, those variables will be re-evaluated for each element. This is useful if you want to create an array whose elements are somewhat different than each other. 1

Additionally, you can set local variables who scope is only visible inside of target. The value of those variables will be randomized on each iteration of repeatedly. 2


Examples

Generating arrays

{
"_gen": "repeatedly",
"n": {
"_gen": "uniformDistribution",
"bounds": [
0,
5
]
},
"target": {
"_gen": "string",
"expr": "#{File.fileName}"
}
}
[
[
"ipsam_quibusdam/perferendis.json"
],
[
"dignissimos_eum/reprehenderit.odp",
"totam_recusandae/nihil.mp4",
"quidem_magni/illum.pptx",
"quos_quis/sunt.js"
],
[
"totam_nesciunt/minima.mp4",
"unde_nihil/voluptates.avi"
],
[
"at_consequatur/non.pages"
],
[
"eveniet_nostrum/quasi.csv",
"id_vitae/fuga.odt",
"quidem_amet/porro.pages"
]
]

Re-evaluating variables

Set iterateVars to an array of variable names to re-evaluate them on each iteration of repeatedly. Notice how a and b hold the same value for each element, but vary between elements.

{
"topic": "sandbox",
"vars": {
"element": {
"_gen": "normalDistribution",
"mean": 50,
"sd": 10
}
},
"value": {
"_gen": "repeatedly",
"n": 3,
"iterateVars": [
"element"
],
"target": {
"a": {
"_gen": "var",
"var": "element"
},
"b": {
"_gen": "var",
"var": "element"
}
}
}
}
[
[
{
"a": 27.56762108826139,
"b": 27.56762108826139
},
{
"a": 63.27705558795537,
"b": 63.27705558795537
},
{
"a": 51.20288560170308,
"b": 51.20288560170308
}
],
[
{
"a": 57.737697110821784,
"b": 57.737697110821784
},
{
"a": 41.78495647279691,
"b": 41.78495647279691
},
{
"a": 48.9073841424445,
"b": 48.9073841424445
}
],
[
{
"a": 63.81626107886015,
"b": 63.81626107886015
},
{
"a": 63.83680003434892,
"b": 63.83680003434892
},
{
"a": 51.024843398991784,
"b": 51.024843398991784
}
]
]

Setting local variables

Set localVars to a map of names and values, just like top-level generator vars. These variables are scoped only to the repeatedly function and will randomize their values on every iteration. This can sometimes serve as a shorthand to using iterateVars.

{
"topic": "sandbox",
"value": {
"_gen": "repeatedly",
"n": 3,
"localVars": {
"element": {
"_gen": "normalDistribution",
"mean": 20,
"sd": 5
}
},
"target": {
"_gen": "var",
"var": "element"
}
}
}
[
[
23.81814187389519,
31.670021212931825,
22.35646944919545
],
[
21.29538685024511,
17.667481556379062,
18.384930627781106
],
[
26.241073384905835,
20.936642680699414,
16.284667055210434
]
]

Specification

JSON schema

{
"type": "object",
"properties": {
"iterateVars": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
},
"localVars": {
"type": "object"
}
},
"required": [
"n",
"target"
]
}