nushell/docs/commands/random.md
Radek Vít 798766b4b5
Remove panics from random integer and make the constraint more idiomatic (#2578)
* Remove panics from random integer and make the constraint more idiomatic

* Add open intervals to NumericRange
2020-09-20 08:41:49 +12:00

122 lines
4.7 KiB
Markdown

# random
Use `random` to generate random values
## bool
* `random bool`: Generate a random boolean value
### bool Flags
* `-b`, `--bias` \<number>: Adjusts the probability of a "true" outcome
### bool Examples
```shell
> random bool
false
```
```shell
> random bool --bias 0.75
true
```
## dice
* `random dice`: Generate a random dice roll
### dice Flags
* `d`, `--dice` \<integer>: The amount of dice being rolled
* `s`, `--sides` \<integer>: The amount of sides a die has
### dice Examples
```shell
> random dice
4
```
```shell
> random dice -d 10 -s 12
───┬────
011
111
211
311
45
53
610
77
83
91
───┴────
```
```shell
> random dice --dice 1024 --sides 16 | histogram | sort-by occurrences
────┬───────┬─────────────┬────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
# │ value │ occurrences │ percentage │ frequency
────┼───────┼─────────────┼────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
0657 │ 75.00% │ ***************************************************************************
11259 │ 77.63% │ *****************************************************************************
2359 │ 77.63% │ *****************************************************************************
31660 │ 78.95% │ ******************************************************************************
41361 │ 80.26% │ ********************************************************************************
51162 │ 81.58% │ *********************************************************************************
6562 │ 81.58% │ *********************************************************************************
7962 │ 81.58% │ *********************************************************************************
8463 │ 82.89% │ **********************************************************************************
9864 │ 84.21% │ ************************************************************************************
101065 │ 85.53% │ *************************************************************************************
111566 │ 86.84% │ **************************************************************************************
121467 │ 88.16% │ ****************************************************************************************
13769 │ 90.79% │ ******************************************************************************************
14172 │ 94.74% │ **********************************************************************************************
15276 │ 100.00% │ ****************************************************************************************************
────┴───────┴─────────────┴────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
```
## uuid
* `random uuid`: Generate a random uuid4 string
### uuid Examples
```shell
> random uuid
8af4de39-acbc-42f0-94d1-7cfad6c01f8b
```
## integer
* `random integer`: Generate a random integer
### integer Flags
* `m`, `--min` \<integer>: The minimum value to generate
* `x`, `--max` \<integer>: The maximum value to generate
### integer Examples
```shell
> random integer
42
```
```shell
> random integer 5000..
8700890823
```
```shell
> random integer ..100
73
```
```shell
> random integer 100000..200000
173400
```