1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
---
title: random functions
menu:
main:
parent: functions
---
Functions for generating random values.
### About randomness
`gomplate` uses Go's [`math/rand`](https://golang.org/pkg/math/rand/) package
to generate pseudo-random numbers. Note that these functions are not suitable
for use in security-sensitive applications, such as cryptography. However,
these functions will not deplete system entropy.
## `random.ASCII`
Generates a random string of a desired length, containing the set of
printable characters from the 7-bit [ASCII](https://en.wikipedia.org/wiki/ASCII)
set. This includes _space_ (' '), but no other whitespace characters.
### Usage
```go
random.ASCII count
```
### Arguments
| name | description |
|------|-------------|
| `count` | _(required)_ the length of the string to produce (number of characters) |
### Examples
```console
$ gomplate -i '{{ random.ASCII 8 }}'
_woJ%D&K
```
## `random.Alpha`
Generates a random alphabetical (`A-Z`, `a-z`) string of a desired length.
### Usage
```go
random.Alpha count
```
### Arguments
| name | description |
|------|-------------|
| `count` | _(required)_ the length of the string to produce (number of characters) |
### Examples
```console
$ gomplate -i '{{ random.Alpha 42 }}'
oAqHKxHiytYicMxTMGHnUnAfltPVZDhFkVkgDvatJK
```
## `random.AlphaNum`
Generates a random alphanumeric (`0-9`, `A-Z`, `a-z`) string of a desired length.
### Usage
```go
random.AlphaNum count
```
### Arguments
| name | description |
|------|-------------|
| `count` | _(required)_ the length of the string to produce (number of characters) |
### Examples
```console
$ gomplate -i '{{ random.AlphaNum 16 }}'
4olRl9mRmVp1nqSm
```
## `random.String`
Generates a random string of a desired length.
By default, the possible characters are those represented by the
regular expression `[a-zA-Z0-9_.-]` (alphanumeric, plus `_`, `.`, and `-`).
A different set of characters can be specified with a regular expression,
or by giving a range of possible characters by specifying the lower and
upper bounds. Lower/upper bounds can be specified as characters (e.g.
`"q"`, or escape sequences such as `"\U0001f0AF"`), or numeric Unicode
code-points (e.g. `48` or `0x30` for the character `0`).
When given a range of Unicode code-points, `random.String` will discard
non-printable characters from the selection. This may result in a much
smaller set of possible characters than intended, so check
the [Unicode character code charts](http://www.unicode.org/charts/) to
verify the correct code-points.
### Usage
```go
random.String count [regex] [lower] [upper]
```
### Arguments
| name | description |
|------|-------------|
| `count` | _(required)_ the length of the string to produce (number of characters) |
| `regex` | _(optional)_ the regular expression that each character must match (defaults to `[a-zA-Z0-9_.-]`) |
| `lower` | _(optional)_ lower bound for a range of characters (number or single character) |
| `upper` | _(optional)_ upper bound for a range of characters (number or single character) |
### Examples
```console
$ gomplate -i '{{ random.String 8 }}'
FODZ01u_
```
```console
$ gomplate -i '{{ random.String 16 `[[:xdigit:]]` }}'
B9e0527C3e45E1f3
```
```console
$ gomplate -i '{{ random.String 20 `[\p{Canadian_Aboriginal}]` }}'
ᗄᖖᣡᕔᕫᗝᖴᒙᗌᘔᓰᖫᗵᐕᗵᙔᗠᓅᕎᔹ
```
```console
$ gomplate -i '{{ random.String 8 "c" "m" }}'
ffmidgjc
```
```console
$ gomplate -i 'You rolled... {{ random.String 3 "⚀" "⚅" }}'
You rolled... ⚅⚂⚁
```
```console
$ gomplate -i 'Poker time! {{ random.String 5 "\U0001f0a1" "\U0001f0de" }}'
Poker time! 🂼🂺🂳🃅🂪
```
## `random.Item`
Pick an element at a random from a given slice or array.
### Usage
```go
random.Item items
```
```go
items | random.Item
```
### Arguments
| name | description |
|------|-------------|
| `items` | _(required)_ the input array |
### Examples
```console
$ gomplate -i '{{ random.Item (seq 0 5) }}'
4
```
```console
$ export SLICE='["red", "green", "blue"]'
$ gomplate -i '{{ getenv "SLICE" | jsonArray | random.Item }}'
blue
```
## `random.Number`
Pick a random integer. By default, a number between `0` and `100`
(inclusive) is chosen, but this range can be overridden.
Note that the difference between `min` and `max` can not be larger than a
63-bit integer (i.e. the unsigned portion of a 64-bit signed integer).
The result is given as an `int64`.
### Usage
```go
random.Number [min] [max]
```
### Arguments
| name | description |
|------|-------------|
| `min` | _(optional)_ The minimum value, defaults to `0`. Must be less than `max`. |
| `max` | _(optional)_ The maximum value, defaults to `100` (if no args provided) |
### Examples
```console
$ gomplate -i '{{ random.Number }}'
55
```
```console
$ gomplate -i '{{ random.Number -10 10 }}'
-3
```
```console
$ gomplate -i '{{ random.Number 5 }}'
2
```
## `random.Float`
Pick a random decimal floating-point number. By default, a number between
`0.0` and `1.0` (_exclusive_, i.e. `[0.0,1.0)`) is chosen, but this range
can be overridden.
The result is given as a `float64`.
### Usage
```go
random.Float [min] [max]
```
### Arguments
| name | description |
|------|-------------|
| `min` | _(optional)_ The minimum value, defaults to `0.0`. Must be less than `max`. |
| `max` | _(optional)_ The maximum value, defaults to `1.0` (if no args provided). |
### Examples
```console
$ gomplate -i '{{ random.Float }}'
0.2029946480303966
```
```console
$ gomplate -i '{{ random.Float 100 }}'
71.28595374161743
```
```console
$ gomplate -i '{{ random.Float -100 200 }}'
105.59119437834909
```
|