Updated smnp.math (markdown)

Bartłomiej Przemysław Pluta
2020-03-27 18:06:56 +01:00
parent 534844d3f2
commit 4158bef959

@@ -1,24 +1,42 @@
# Functions # Functions
## `random(min: int, max: int)` ## random
Returns a random `int` from a given range _exclusively_. ```
random(min: int, max: int)
random(min: float, max: float)
```
Returns a random number from a given range _exclusively_.
## `random(min: float, max: float)` #### Output
Returns a random `float` from a given range _exclusively_. * `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. 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. Returns the greatest number of given list.
## `sample(list: list)` ## sample
```
sample(list: list)
```
Returns a random item of given list. Returns a random item of given list.
## `pick(items: list<map<string><>>)` ## pick
Returns a random item of given list using a configuration maps. It is a more generic version of `sample()` function. ```
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 #### Arguments
* `items` - list of configuration maps. Each map has to match following schema: * `items` - list of configuration maps. Each map has to match following schema (all keys are required):
| KEY | VALUE | | 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. The sum of `chance` value of each item should be equal to 100.
### Example #### Example
``` ```
items = [ items = [
{ chance -> 70, value -> "70%" }, { chance -> 70, value -> "70%" },
@@ -47,19 +65,25 @@ println("5% : ", collected.countBy("5%"));
# 5% : 4986 # 5% : 4986
``` ```
## `pick(...items: map<string><>)` ## mod
See `pick(items: list<map<string><>>)` ```
mod(a: int, b: int)
## `mod(a: int, b: int)` ```
Returns the remainder after division of `a` by `b`. 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`. 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] 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). Gets the random `float` value uniformly distributed between 0 (inclusive) and 1 (exclusive).