MCPcopy Create free account
hub / github.com/Hieromon/AutoConnect / _random

Method _random

examples/WebCamServer/ESP32WebCam.cpp:494–512  ·  view source on GitHub ↗

* Generates pseudo-random numbers. * This function is only quoted for boundary string generation for multipart * content. * @param max Maximum range of random numbers to be generated. * @return A generated random number. */

Source from the content-addressed store, hash-verified

492 * @return A generated random number.
493 */
494long ESP32WebCam::_random(long max) {
495 uint32_t x = esp_random();
496 uint64_t m = uint64_t(x) * uint64_t(max);
497 uint32_t l = uint32_t(m);
498 if (l < max) {
499 uint32_t t = -max;
500 if (t >= max) {
501 t -= max;
502 if (t >= max)
503 t %= max;
504 }
505 while (l < t) {
506 x = esp_random();
507 m = uint64_t(x) * uint64_t(max);
508 l = uint32_t(m);
509 }
510 }
511 return m >> 32;
512}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected