summaryrefslogtreecommitdiff
path: root/shared-bindings/random
diff options
context:
space:
mode:
Diffstat (limited to 'shared-bindings/random')
-rw-r--r--shared-bindings/random/__init__.c60
1 files changed, 27 insertions, 33 deletions
diff --git a/shared-bindings/random/__init__.c b/shared-bindings/random/__init__.c
index 83698eac5..c0124df41 100644
--- a/shared-bindings/random/__init__.c
+++ b/shared-bindings/random/__init__.c
@@ -33,12 +33,7 @@
#include "shared-bindings/random/__init__.h"
#include "supervisor/shared/translate.h"
-//| :mod:`random` --- psuedo-random numbers and choices
-//| ========================================================
-//|
-//| .. module:: random
-//| :synopsis: psuedo-random numbers and choices
-//| :platform: SAMD21, ESP8266
+//| """pseudo-random numbers and choices
//|
//| The `random` module is a strict subset of the CPython `cpython:random`
//| module. So, code written in CircuitPython will work in CPython but not
@@ -49,13 +44,13 @@
//| Once seeded, it will be deterministic, which is why its bad for cryptography.
//|
//| .. warning:: Numbers from this module are not cryptographically strong! Use
-//| bytes from `os.urandom` directly for true randomness.
+//| bytes from `os.urandom` directly for true randomness."""
//|
-//| .. function:: seed(seed)
-//|
-//| Sets the starting seed of the random number generation. Further calls to
-//| `random` will return deterministic results afterwards.
+//| def seed(seed: Any) -> Any:
+//| """Sets the starting seed of the random number generation. Further calls to
+//| `random` will return deterministic results afterwards."""
+//| ...
//|
STATIC mp_obj_t random_seed(mp_obj_t seed_in) {
mp_uint_t seed = mp_obj_get_int_truncated(seed_in);
@@ -64,9 +59,9 @@ STATIC mp_obj_t random_seed(mp_obj_t seed_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_seed_obj, random_seed);
-//| .. function:: getrandbits(k)
-//|
-//| Returns an integer with *k* random bits.
+//| def getrandbits(k: Any) -> Any:
+//| """Returns an integer with *k* random bits."""
+//| ...
//|
STATIC mp_obj_t random_getrandbits(mp_obj_t num_in) {
int n = mp_obj_get_int(num_in);
@@ -77,10 +72,9 @@ STATIC mp_obj_t random_getrandbits(mp_obj_t num_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_getrandbits_obj, random_getrandbits);
-//| .. function:: randrange(stop)
-//| randrange(start, stop, step=1)
-//|
-//| Returns a randomly selected integer from ``range(start, stop, step)``.
+//| def randrange(stop: Any) -> Any:
+//| """Returns a randomly selected integer from ``range(start, stop, step)``."""
+//| ...
//|
STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) {
mp_int_t start = 0;
@@ -120,10 +114,10 @@ STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(random_randrange_obj, 1, 3, random_randrange);
-//| .. function:: randint(a, b)
-//|
-//| Returns a randomly selected integer between a and b inclusive. Equivalent
-//| to ``randrange(a, b + 1, 1)``
+//| def randint(a: Any, b: Any) -> Any:
+//| """Returns a randomly selected integer between a and b inclusive. Equivalent
+//| to ``randrange(a, b + 1, 1)``"""
+//| ...
//|
STATIC mp_obj_t random_randint(mp_obj_t a_in, mp_obj_t b_in) {
mp_int_t a = mp_obj_get_int(a_in);
@@ -135,10 +129,10 @@ STATIC mp_obj_t random_randint(mp_obj_t a_in, mp_obj_t b_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(random_randint_obj, random_randint);
-//| .. function:: choice(seq)
-//|
-//| Returns a randomly selected element from the given sequence. Raises
-//| IndexError when the sequence is empty.
+//| def choice(seq: Any) -> Any:
+//| """Returns a randomly selected element from the given sequence. Raises
+//| IndexError when the sequence is empty."""
+//| ...
//|
STATIC mp_obj_t random_choice(mp_obj_t seq) {
mp_int_t len = mp_obj_get_int(mp_obj_len(seq));
@@ -149,19 +143,19 @@ STATIC mp_obj_t random_choice(mp_obj_t seq) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_choice_obj, random_choice);
-//| .. function:: random()
-//|
-//| Returns a random float between 0 and 1.0.
+//| def random() -> Any:
+//| """Returns a random float between 0 and 1.0."""
+//| ...
//|
STATIC mp_obj_t random_random(void) {
return mp_obj_new_float(shared_modules_random_random());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(random_random_obj, random_random);
-//| .. function:: uniform(a, b)
-//|
-//| Returns a random float between a and b. It may or may not be inclusive
-//| depending on float rounding.
+//| def uniform(a: Any, b: Any) -> Any:
+//| """Returns a random float between a and b. It may or may not be inclusive
+//| depending on float rounding."""
+//| ...
//|
STATIC mp_obj_t random_uniform(mp_obj_t a_in, mp_obj_t b_in) {
mp_float_t a = mp_obj_get_float(a_in);