Skip to content

Commit

Permalink
document count option of pickRandom helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
RafeArnold committed Nov 27, 2024
1 parent 50e8450 commit d5d4f5d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions _docs/response-templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ A value can be randomly selected from a literal list:
{% raw %}

```handlebars
{{{pickRandom '1' '2' '3'}}}
{{pickRandom '1' '2' '3'}}
```

{% endraw %}
Expand All @@ -1060,7 +1060,30 @@ Or from a list passed as a parameter:
{% raw %}

```handlebars
{{{pickRandom (jsonPath request.body '$.names')}}}
{{pickRandom (jsonPath request.body '$.names')}}
```

{% endraw %}

If you desire multiple unique elements to be randomly pulled from the list, a `count` option can be supplied to the
helper.
In this case, the result will be a list, instead of a single value.
For example, the following template:

{% raw %}

```handlebars
{{pickRandom 1 2 3 4 5 count=3}}
```

{% endraw %}

will produce a list similar to the following:

{% raw %}

```handlebars
[3, 5, 2]
```

{% endraw %}
Expand Down

0 comments on commit d5d4f5d

Please sign in to comment.