|
| 1 | +""" |
| 2 | +I Language Random module. |
| 3 | +Version: 0.1.0 |
| 4 | +
|
| 5 | +Copyright (c) 2023-present ElBe Development. |
| 6 | +
|
| 7 | +Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | +copy of this software and associated documentation files (the 'Software'), |
| 9 | +to deal in the Software without restriction, including without limitation |
| 10 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | +and/or sell copies of the Software, and to permit persons to whom the |
| 12 | +Software is furnished to do so, subject to the following conditions: |
| 13 | +
|
| 14 | +The above copyright notice and this permission notice shall be included in |
| 15 | +all copies or substantial portions of the Software. |
| 16 | +
|
| 17 | +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | +DEALINGS IN THE SOFTWARE. |
| 24 | +""" |
| 25 | + |
| 26 | +########### |
| 27 | +# IMPORTS # |
| 28 | +########### |
| 29 | + |
| 30 | +import random |
| 31 | +from typing import ( |
| 32 | + Any, |
| 33 | + List, |
| 34 | +) |
| 35 | + |
| 36 | + |
| 37 | +########### |
| 38 | +# RANDINT # |
| 39 | +########### |
| 40 | + |
| 41 | +def randint(minimum: int, maximum: int) -> int: |
| 42 | + """Generates a random number. |
| 43 | +
|
| 44 | + :param minimum: Lowest possible value. |
| 45 | + :param maximum: Highest possible value. |
| 46 | + :return: Random number between minimum and maximum. |
| 47 | + """ |
| 48 | + |
| 49 | + return random.randint(minimum, maximum) |
| 50 | + |
| 51 | + |
| 52 | +########### |
| 53 | +# CHOICES # |
| 54 | +########### |
| 55 | + |
| 56 | +def choices(iterable: List, choices: int = 1) -> Any: |
| 57 | + """Returns a random value from a given list. |
| 58 | +
|
| 59 | + :param iterable: List to return a random value from. |
| 60 | + :param choices: Number of choices to return form the iterable. If choices is bigger than the iterable, the remaining |
| 61 | + values will be skipped. |
| 62 | + :return: Random value(s) from iterable. |
| 63 | + """ |
| 64 | + |
| 65 | + if choices == 1: |
| 66 | + return random.choice(iterable) |
| 67 | + else: |
| 68 | + return random.choices(iterable) |
| 69 | + |
| 70 | +########### |
| 71 | +# SHUFFLE # |
| 72 | +########### |
0 commit comments