summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2023-12-28 14:25:29 -0800
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-12-29 19:37:27 +0100
commite40b9fbbcf28c07ad90ae1048e144888414074d7 (patch)
treecc2babd1851fa23c375c2e48beb45d6898b5ef1f /docs
parent9cd8fbb3324cb58e06095167cbea952619dd3201 (diff)
tpl/math: Add math.Rand template function
Closes #11833
Diffstat (limited to 'docs')
-rw-r--r--docs/content/en/functions/math/Rand.md44
-rw-r--r--docs/content/en/getting-started/glossary.md10
2 files changed, 54 insertions, 0 deletions
diff --git a/docs/content/en/functions/math/Rand.md b/docs/content/en/functions/math/Rand.md
new file mode 100644
index 000000000..4cdf02fd3
--- /dev/null
+++ b/docs/content/en/functions/math/Rand.md
@@ -0,0 +1,44 @@
+---
+title: math.Rand
+description: Returns a pseudo-random number in the half-open interval [0.0, 1.0).
+categories: []
+keywords: []
+action:
+ aliases: []
+ related: []
+ returnType: float64
+ signatures: [math.Rand]
+---
+
+The `math.Rand` function returns a pseudo-random number in the [half-open interval] [0.0, 1.0).
+
+```go-html-template
+{{ math.Rand }} → 0.6312770459590062
+```
+
+To generate a random integer in the [closed interval] [0, 5]:
+
+```go-html-template
+{{ math.Rand | mul 6 | math.Floor }}
+```
+
+To generate a random integer in the closed interval [1, 6]:
+
+```go-html-template
+{{ math.Rand | mul 6 | math.Ceil }}
+```
+
+To generate a random float, with one digit after the decimal point, in the closed interval [0, 4.9]:
+
+```go-html-template
+{{ div (math.Rand | mul 50 | math.Floor) 10 }}
+```
+
+To generate a random float, with one digit after the decimal point, in the closed interval [0.1, 5.0]:
+
+```go-html-template
+{{ div (math.Rand | mul 50 | math.Ceil) 10 }}
+```
+
+[closed interval]: /getting-started/glossary/#interval
+[half-open interval]: /getting-started/glossary/#interval
diff --git a/docs/content/en/getting-started/glossary.md b/docs/content/en/getting-started/glossary.md
index edf64ab89..dce3d1527 100644
--- a/docs/content/en/getting-started/glossary.md
+++ b/docs/content/en/getting-started/glossary.md
@@ -147,6 +147,16 @@ A numeric data type without a fractional component. For example, `42`.
Software design and development efforts that enable [localization](#localization). See the [W3C definition](https://www.w3.org/International/questions/qa-i18n). Abbreviated i18n.
+###### interval
+
+An [interval](https://en.wikipedia.org/wiki/Interval_(mathematics)) is a range of numbers between two endpoints: closed, open, or half-open.
+
+- A _closed_ interval, denoted by brackets, includes its endpoints. For example, [0,&nbsp;1]&nbsp;is the interval where `0 <= x <= 1`.
+
+- An _open_ interval, denoted by parenthesis, excludes its endpoints. For example, (0,&nbsp;1)&nbsp;is the interval where `0 < x < 1`.
+
+- A _half-open_ interval includes only one of its endpoints. For example, (0,&nbsp;1]&nbsp;is the _left-open_ interval where `0 < x <= 1`, while [0,&nbsp;1)&nbsp;is the _right-open_ interval where `0 <= x < 1`.
+
###### kind
See [page kind](#page-kind).