-
Hello, I just uploaded the latest release for ESP8266 2M+, V1.20. The board is a ESP8266-12F NodeMCU Lolin V3. According to the docs, the "random" module should come with a heap of functions (like randint() or uniform()). However, when trying to access these on my 8266 dev board, it appears only seed() and getrandbits() are present. >>> import random
>>> random.uniform(13, 25)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'uniform' Could someone please tell me what I am missing ? Thanks in advance for your help ! EDIT : I also had a question about espnow, but found my answer, so deleted it |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
As you tell, the esp8266 random module does implement only a small subset of the random module to save flash space for devices with small memory. Building your own firmware, you can change that by setting:
In the mpconfigport.h of the ESP8266 port, or better in the mpconfigboard.h of the GENERIC board section. Generally, the configuration could be changed to support more features with the 2MB version of the firmware. Only someone has to make the change, test it and make a PR for it. |
Beta Was this translation helpful? Give feedback.
-
I know this has been answered but for future people like myself wanting randrange: import random
def randrange(start, stop):
return random.getrandbits(16) % (stop + 1 - start) + start |
Beta Was this translation helpful? Give feedback.
-
Interesting. No, I don't have a random.py in my project. I'm using To discover what was available in random, in the mpy case, I did |
Beta Was this translation helpful? Give feedback.
As you tell, the esp8266 random module does implement only a small subset of the random module to save flash space for devices with small memory. Building your own firmware, you can change that by setting:
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
In the mpconfigport.h of the ESP8266 port, or better in the mpconfigboard.h of the GENERIC board section. Generally, the configuration could be changed to support more features with the 2MB version of the firmware. Only someone has to make the change, test it and make a PR for it.