Updated smnp.math (markdown)
62
smnp.math.md
62
smnp.math.md
@@ -1,24 +1,42 @@
|
||||
# Functions
|
||||
## `random(min: int, max: int)`
|
||||
Returns a random `int` from a given range _exclusively_.
|
||||
## random
|
||||
```
|
||||
random(min: int, max: int)
|
||||
random(min: float, max: float)
|
||||
```
|
||||
Returns a random number from a given range _exclusively_.
|
||||
|
||||
## `random(min: float, max: float)`
|
||||
Returns a random `float` from a given range _exclusively_.
|
||||
#### Output
|
||||
* `int` if passed arguments are of `int` type
|
||||
* `float` if passed arguments are of `float` type
|
||||
|
||||
## `min(numbers: list<int, float>)`
|
||||
## min
|
||||
```
|
||||
min(numbers: list<int, float>)
|
||||
```
|
||||
Returns the smallest number of given list.
|
||||
|
||||
## `max(numbers: list<int, float>)`
|
||||
## max
|
||||
```
|
||||
max(numbers: list<int, float>)
|
||||
```
|
||||
Returns the greatest number of given list.
|
||||
|
||||
## `sample(list: list)`
|
||||
## sample
|
||||
```
|
||||
sample(list: list)
|
||||
```
|
||||
Returns a random item of given list.
|
||||
|
||||
## `pick(items: list<map<string><>>)`
|
||||
Returns a random item of given list using a configuration maps. It is a more generic version of `sample()` function.
|
||||
## pick
|
||||
```
|
||||
pick(items: list<map<string><>>)
|
||||
pick(...items: map<string><>)
|
||||
```
|
||||
Returns a random item of given list using a configuration maps. It is a more generic version of [smnp.math::sample](https://github.com/bartlomiej-pluta/smnp/wiki/smnp.math#sample) function.
|
||||
|
||||
### Arguments
|
||||
* `items` - list of configuration maps. Each map has to match following schema:
|
||||
#### Arguments
|
||||
* `items` - list of configuration maps. Each map has to match following schema (all keys are required):
|
||||
|
||||
| KEY | VALUE |
|
||||
|:------:|:----------------------------------------------------------------------------------------------:|
|
||||
@@ -27,7 +45,7 @@ Returns a random item of given list using a configuration maps. It is a more gen
|
||||
|
||||
The sum of `chance` value of each item should be equal to 100.
|
||||
|
||||
### Example
|
||||
#### Example
|
||||
```
|
||||
items = [
|
||||
{ chance -> 70, value -> "70%" },
|
||||
@@ -47,19 +65,25 @@ println("5% : ", collected.countBy("5%"));
|
||||
# 5% : 4986
|
||||
```
|
||||
|
||||
## `pick(...items: map<string><>)`
|
||||
See `pick(items: list<map<string><>>)`
|
||||
|
||||
## `mod(a: int, b: int)`
|
||||
## mod
|
||||
```
|
||||
mod(a: int, b: int)
|
||||
```
|
||||
Returns the remainder after division of `a` by `b`.
|
||||
|
||||
## `range(begin: int, end: int, step: int = 1)`
|
||||
## range
|
||||
```
|
||||
range(begin: int, end: int, step: int = 1)
|
||||
```
|
||||
Returns a list contained of integers from `begin` (inclusive) to `end` (exclusive) with given `step`.
|
||||
|
||||
### Example
|
||||
#### Example
|
||||
```
|
||||
println(range(4, 20, 2)); # [4, 6, 8, 10, 12, 14, 16, 18]
|
||||
```
|
||||
|
||||
## `random()`
|
||||
## random
|
||||
```
|
||||
random()
|
||||
```
|
||||
Gets the random `float` value uniformly distributed between 0 (inclusive) and 1 (exclusive).
|
||||
Reference in New Issue
Block a user