8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 89d6b89 commit 2bb32bdCopy full SHA for 2bb32bd
cores/esp32/WMath.cpp
@@ -37,10 +37,23 @@ void randomSeed(unsigned long seed)
37
38
long random(long howbig)
39
{
40
- if(howbig == 0) {
41
- return 0;
+ uint32_t x = esp_random();
+ uint64_t m = uint64_t(x) * uint64_t(howbig);
42
+ uint32_t l = uint32_t(m);
43
+ if (l < howbig) {
44
+ uint32_t t = -howbig;
45
+ if (t >= howbig) {
46
+ t -= howbig;
47
+ if (t >= howbig)
48
+ t %= howbig;
49
+ }
50
+ while (l < t) {
51
+ x = esp_random();
52
+ m = uint64_t(x) * uint64_t(howbig);
53
+ l = uint32_t(m);
54
55
}
- return esp_random() % howbig;
56
+ return m >> 32;
57
58
59
long random(long howsmall, long howbig)
0 commit comments