@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+
+* Enabled extra functions for the `random` module.
## [1.5.0] - 2024-10-06
### Added
@@ -5,7 +5,7 @@ App(
entry_point="upython",
stack_size=4 * 1024,
fap_category="Tools",
- fap_version="1.5",
+ fap_version="1.6",
fap_description="Compile and execute MicroPython scripts",
fap_icon="icon.png",
fap_icon_assets="images",
@@ -23,6 +23,11 @@ import io
copy_dict(flipperzero.io, io)
+import flipperzero.random
+import random
+copy_dict(flipperzero.random, random)
now = datetime.datetime.now()
project = 'uPython'
@@ -452,7 +452,7 @@ Functions
I/O
---
-Read and write files on the SD card.
+Read and write SD card files.
Constants
~~~~~~~~~
@@ -475,6 +475,22 @@ Classes
.. autoclass:: io.TextFileIO
:members: name, read, readline, readlines, readable, writable, write, flush, seek, tell, close, __enter__, __exit__, __del__
+Random
+------
+Generate pseudo-random number for various use cases.
+Functions
+~~~~~~~~~
+.. autofunction:: random.random
+.. autofunction:: random.uniform
+.. autofunction:: random.randrange
+.. autofunction:: random.getrandbits
+.. autofunction:: random.randint
+.. autofunction:: random.choice
+.. autofunction:: random.seed
Built-In
--------
@@ -0,0 +1,87 @@
+def random() -> float:
+ '''
+ Get a random float value between 0.0 (inclusive) and 1.0 (exclusive).
+ :returns: The random value.
+ .. versionadded:: 1.6.0
+ pass
+def randrange(start: int, stop: int, step: int = 1) -> int:
+ Get a random integer between ``start`` (inclusive) and ``stop``
+ (exclusive) with an optional ``step`` between the values.
+ :param start: The start value.
+ :param stop: The end value.
+ :param step: The optional step value.
+ .. hint::
+ This function does only generate integer values.
+def randint(a: int, b: int) -> int:
+ Get a random integer between ``a`` (inclusive) and ``b`` (inclusive).
+ :param a: The lower value.
+ :param b: The upper value.
+def choice[T](seq: list[T]) -> T:
+ Get a random element from the provided sequence.
+ :param seq: The sequence to use.
+ :returns: A random element.
+def getrandbits(k: int) -> int:
+ Get ``k`` random bits.
+ :param k: The number of bits.
+ :returns: The random bits.
+def uniform(a: float, b: float) -> float:
+ Get a random float value between ``a`` (inclusive) and ``b`` (inclusive).
+def seed(a: int) -> None:
+ Initialize the random number generator.
+ :param a: The initialization value to use.
+ Random generator seeding is done automatically, so there is no need to call this function.
@@ -1 +1 @@
-Subproject commit 29091048ae9a613070da21b373062a450f7ecd08
+Subproject commit 242fff05599d97faafab563a827dd86791c0cbee
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "flipperzero"
-version = "1.5.0"
+version = "1.6.0"
authors = [
{ name = "Oliver Fabel" },
]