Просмотр исходного кода

add extra random functions and docs

Oliver Fabel 1 год назад
Родитель
Сommit
524ece4355
7 измененных файлов с 116 добавлено и 4 удалено
  1. 4 0
      CHANGELOG.md
  2. 1 1
      application.fam
  3. 5 0
      docs/pages/conf.py
  4. 17 1
      docs/pages/reference.rst
  5. 87 0
      flipperzero/random.py
  6. 1 1
      lib/micropython
  7. 1 1
      pyproject.toml

+ 4 - 0
CHANGELOG.md

@@ -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

+ 1 - 1
application.fam

@@ -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",

+ 5 - 0
docs/pages/conf.py

@@ -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'

+ 17 - 1
docs/pages/reference.rst

@@ -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
 --------
 

+ 87 - 0
flipperzero/random.py

@@ -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.
+    :returns: The random value.
+
+    .. versionadded:: 1.6.0
+
+    .. hint::
+
+        This function does only generate integer values.
+    '''
+    pass
+
+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.
+    :returns: The random value.
+
+    .. versionadded:: 1.6.0
+    '''
+    pass
+
+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.
+
+    .. versionadded:: 1.6.0
+    '''
+    pass
+
+def getrandbits(k: int) -> int:
+    '''
+    Get ``k`` random bits. 
+
+    :param k: The number of bits.
+    :returns: The random bits.
+
+    .. versionadded:: 1.6.0
+    '''
+    pass
+
+def uniform(a: float, b: float) -> float:
+    '''
+    Get a random float value between ``a`` (inclusive) and ``b`` (inclusive).
+
+    :param a: The lower value.
+    :param b: The upper value.
+    :returns: The random value.
+
+    .. versionadded:: 1.6.0
+    '''
+    pass
+
+def seed(a: int) -> None:
+    '''
+    Initialize the random number generator. 
+
+    :param a: The initialization value to use.
+
+    .. versionadded:: 1.6.0
+
+    .. hint::
+
+        Random generator seeding is done automatically, so there is no need to call this function.
+    '''
+    pass

+ 1 - 1
lib/micropython

@@ -1 +1 @@
-Subproject commit 29091048ae9a613070da21b373062a450f7ecd08
+Subproject commit 242fff05599d97faafab563a827dd86791c0cbee

+ 1 - 1
pyproject.toml

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
 
 [project]
 name = "flipperzero"
-version = "1.5.0"
+version = "1.6.0"
 authors = [
     { name = "Oliver Fabel" },
 ]