mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-09 20:30:02 +03:00
parent
9cd8fbb332
commit
e40b9fbbcf
5 changed files with 71 additions and 6 deletions
44
docs/content/en/functions/math/Rand.md
Normal file
44
docs/content/en/functions/math/Rand.md
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue