# Random() is much too slow

**URL:** <https://forum.arduino.cc/t/random-is-much-too-slow/1399198>\
**Category:** UNO R4 WiFi\
**Created:** [July 31, 2025, 11:20am UTC](https://forum.arduino.cc/t/random-is-much-too-slow/1399198 "2025-07-31T11:20:49Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [August 6, 2025, 9:00am UTC](https://forum.arduino.cc/t/random-is-much-too-slow/1399198/21 "2025-08-06T09:00:38Z")

</div>

> [@vvb333007](#):
>
> We are trying to find a faster replacement for "random()"

But we haven't clearly specified how good a random number we need.  
There's little point in trying to gather entropy from multiple sources if all you want is for your hand-held game to play differently each time it is run. The pseudo-random number generator that you get if you supply a seed via `randomSeed()` takes 4us on an R4, and is probably fine for most applications (there weren't many complaints about the R3 random(), which is also PRNG.)

It's not good for cryptographic applications, though.

The R4 _has_ a True Random number generator, that is supposed to be good enough for crypto. There shouldn't be any need to search futher than that, assuming that it's "fast enough." The current implementation in Arduino seems to take about 90000us, which is the complaint. That's a "bug", IMO. It should only take about 20us. (which is still 5x slower than the PRNG.) That fetches 16 bytes worth of TRN, and 12 are just thrown away. With a bit more code and some static storage, the average speed could be down close to the PRNG speed. (and in theory, some of the generation time could be done in the background...) (Hmm. At the expense of some power consumption. There was a bug on the Renesas github where turning off the SCE did not fully turn off the TRNG, leading to 130uA or so of excess current in sleep modes..)

> [@Coding\_Badly](#):
>
> There is no such thing as "increase security" with simple generators.

I dunno. That's like saying a 6 letter password doesn't have any increased security over a 4digit pin. _OF COURSE_ it's "better." And of course seeding a PRNG with a bit of entropy is better than letting it be seeded with a built-in constant. It's not _mathematically_ better, but it's slightly better in a _practical_ sense. You need to understand your "attack surface" to guess whether it's "good enough."  
(I think I've told the story about designing an "encryption scheme" that led to the company I work for being blackmailed ("pay me or I'll tell everyone how to decrypt your stuff!")... 🙂 )

(BTW, if you're interested in doing cryptographically secure stuff, getting a good random number is probably a minor problem compared to figuring out how to do some sort of secure key storage.)

---

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [August 6, 2025, 4:16pm UTC](https://forum.arduino.cc/t/random-is-much-too-slow/1399198/22 "2025-08-06T16:16:21Z")

</div>

For this thread we haven't heard back from OP, and seem to have solved the R4 random() speed problem by seeding randomSeed().

> [@westfw](#):
>
> It's not good for cryptographic applications, though.

Do cryptographic applications typically require large volumes of high quality random numbers? I thought the high quality is needed for key generation, but once you have the keys, then the algorithms are just algorithms. Maybe a high volume of commercial transactions would require a fast stream of high quality keys, but I can't see running an Arduino on the back end of that.

For large simulations, high quality, repeatable, fast PRNGs make sense, but I don't understand the use-case of a fast true RNG on an Arduino.

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [August 8, 2025, 11:24pm UTC](https://forum.arduino.cc/t/random-is-much-too-slow/1399198/23 "2025-08-08T23:24:19Z")

</div>

> [@westfw](#):
>
> some of the generation time could be done in the background

Well, THAT'S not going to happen. The bottom level code provided by Renesas has its own wait loops, is completely obscure, and doesn't show any signs of being able to be "backgrounded." (it looks a bit like everything funnels through some multiplexed SCE addresses, so leaving the RNG running might interfere with anything else that tried to use the SCE. Sigh.  
Weird code, too...

> <https://github.com/renesas/fsp/blob/master/ra/fsp/src/r_sce/crypto_procedures/src/sce5/plainkey/primitive/hw_sce_p09.c#L39>

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 4, 2026, 11:24pm UTC](https://forum.arduino.cc/t/random-is-much-too-slow/1399198/24 "2026-02-04T23:24:46Z")

</div>

Closed on February 4, 2026, 11:24pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/random-is-much-too-slow/1399198.md?page=1)
