hugo/docs/content/en/functions/math/Rand.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.1 KiB

title description categories keywords action
math.Rand Returns a pseudo-random number in the half-open interval [0.0, 1.0).
aliases related returnType signatures
float64
math.Rand

{{< new-in 0.121.2 >}}

The math.Rand function returns a pseudo-random number in the half-open interval [0.0, 1.0).

{{ math.Rand }} → 0.6312770459590062

To generate a random integer in the closed interval [0, 5]:

{{ math.Rand | mul 6 | math.Floor }}

To generate a random integer in the closed interval [1, 6]:

{{ 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]:

{{ 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]:

{{ div (math.Rand | mul 50 | math.Ceil) 10 }}