From 03ff7a124232b24924414ec7b87e1c9e8c2ef6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Przemys=C5=82aw=20Pluta?= Date: Wed, 25 Mar 2020 20:22:34 +0100 Subject: [PATCH] Updated smnp.math (markdown) --- smnp.math.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/smnp.math.md b/smnp.math.md index f9a2da5..f509fd0 100644 --- a/smnp.math.md +++ b/smnp.math.md @@ -1,11 +1,65 @@ # Functions ## `random(min: int, max: int)` +Returns a random `int` from a given range _exclusively_. + ## `random(min: float, max: float)` +Returns a random `float` from a given range _exclusively_. + ## `min(numbers: list)` +Returns the smallest number of given list. + ## `max(numbers: list)` +Returns the greatest number of given list. + ## `sample(list: list)` +Returns a random item of given list. + ## `pick(items: list<>>)` +Returns a random item of given list using a configuration maps. It is a more generic version of `sample()` function. + +### Arguments +* `items` - list of configuration maps. Each map has to match following schema: + +| KEY | VALUE | +|:------:|:----------------------------------------------------------------------------------------------:| +| chance | An `int` value which determines the percentage (0-100) chances to draw this item. | +| value | An value to be returned if this item will be drawn. | + +The sum of `chance` value of each item should be equal to 100. + +### Example +``` +items = [ + { chance -> 70, value -> "70%" }, + { chance -> 25, value -> "25%" }, + { chance -> 5, value -> "5%" } +]; + +collected = 100000 ^ pick(items); + +println("70% : ", collected.countBy("70%")); +println("25% : ", collected.countBy("25%")); +println("5% : ", collected.countBy("5%")); + +# Output: +# 75% : 70214 +# 25% : 24800 +# 5% : 4986 +``` + ## `pick(...items: map<>)` +See `pick(items: list<>>)` + ## `mod(a: int, b: int)` -## `range(begin: int, end: int)` -## `random()` \ No newline at end of file +Returns the remainder after division of `a` by `b`. + +## `range(begin: int, end: int, step: int = 1)` +Returns a list contained of integers from `begin` (inclusive) to `end` (exclusive) with given `step`. + +### Example +``` +println(range(4, 20, 2)); # [4, 6, 8, 10, 12, 14, 16, 18] +``` + +## `random()` +Gets the random `float` value uniformly distributed between 0 (inclusive) and 1 (exclusive). \ No newline at end of file