# Same randomseed, but got defferent random numbers

I tried folloing sketch on my Arduino UNO
(Arduino IDE 1.8.8, Arduino AVR Board by Arduino 1.6.22)

``````#include <limits.h>
void setup() {
Serial.begin(38400);
}

void loop() {
for (int i = 0; i < 10; i++) {
randomSeed(0); //always 0
Serial.print(i);
Serial.print(" ");
Serial.println(random(INT_MAX));
}
while (1);
}
``````

0 16807
1 23709
2 28233
3 405
4 16358
5 4822
6 6883
7 14281
8 23850
9 29590

I tried same sketch on the m0/PRO (Arduino SAMD Board 32-bits ARM Cortex-M0+) by Arduino 1.6.20,
got this.

0 1481765933
1 1085377743
2 1270216262
3 1191391529
4 812669700
5 553475508
6 445349752
7 1344887256
8 730417256
9 1812158119

and on ESP32(M5Stack), I got different numbers on every boot, every loop…

I expected 10 same numbers like this,
On PC(Win10, Cygwin, gcc 7.3.0)

``````#include <stdlib.h>
#include <stdio.h>

int main(void){
for(int i=0;i<10;i++){
srandom(0);
printf("%d %d\n",i,random());
}
return 0;
}
``````

result:
0 577655601
1 577655601
2 577655601
3 577655601
4 577655601
5 577655601
6 577655601
7 577655601
8 577655601
9 577655601

Does random() retrun same numbers after randomSeed()/srandom() with same value ?
Why Arduinos return defferent numbers?

Does random() retrun same numbers after randomSeed()/srandom() with same value ?

randomSeed(someValue) initialises the random number generated based on the number used. Using the same number will initialise it the same way each time.

Why Arduinos return defferent numbers?

Presumably because their hardware is different

tnx, UKHeliBob,

randomSeed(someValue) initialises the random number generated based on the number used. Using the same number will initialise it the same way each time.

I know, and I hope so.

Look again my sketch and its results, please.

I called randomSeed(0) every time in loop. But random(INT_MAX) after randomSeed(0) NOT returned same number. Why?

OK. I see what you mean

This may be of interest randomSeed(0) ignored

Too bad the documentation for randomSeed() doesn't bother to say that the value 0 will be ignored.

For ESP32, I have seen somehere that the seed is based on some value from the wifi noise.

Thanks all, I understand and tried non-zero number on randomSeed, then I got same numbers by random().