I get about 98 ms, pretty consistently. (~97900 us, using micros())
The Arduino code for R4 boards reads:
static long trng()
{
uint32_t value[4];
if (HW_SCE_McuSpecificInit() != FSP_SUCCESS)
return -1;
HW_SCE_RNG_Read(value);
return (long)value[0] >= 0 ? value[0] : -value[0];
}
Apparently almost ALL of this time is spent in HW_SCE_McuSpecificInit(), which doesn't remember that it has already been initialized! (sigh. Cursed vendor libraries!)
The time goes down to 20us. That's still about 5x slower than the PRNG algorithm, but it's certainly better!
Test sketch:
extern "C" {
fsp_err_t HW_SCE_McuSpecificInit(void);
fsp_err_t HW_SCE_RNG_Read(uint32_t * OutData_Text);
};
void setup() {
Serial.begin(115200);
while (!Serial)
;
randomSeed(1235);
}
uint32_t startTime, openTime, getTime, closeTime, endTime;
static long trng() {
uint32_t value[4];
static bool SCE_inited = false;
if (!SCE_inited) {
if (HW_SCE_McuSpecificInit() != FSP_SUCCESS) {
Serial.println("SCE Init failedĀ®");
return -1;
}
SCE_inited = true;
}
openTime = micros();
HW_SCE_RNG_Read(value);
return (long)value[0] >= 0 ? value[0] : -value[0];
}
void loop() {
delay(2000);
Serial.println(__FILE__);
startTime = micros();
int x = random(10000);
endTime = micros();
Serial.print("simple Micros: ");
Serial.println(endTime - startTime);
startTime = micros();
x = trng();
endTime = micros();
Serial.print("trng SCE Init: ");
Serial.println(openTime - startTime);
Serial.print("trng total: ");
Serial.println(endTime - startTime);
}