Hello,
I am trying to write a simple code to it generate three random numbers within a set of parameters. Those parameters are that the first number be random between 0 and 255. The second being random based off the first, if the first is equal to or above 128 then it will make a number 128 or lower. If the first is lower than 128 then it will create a number from 128 to 255.
So it runs and does as I want for the most part, however it always creates the same sequence of three numbers. I am curious as to why, if someone can give me a hint or explain how putting my functions outside the loop may be impacting it. I am still trying to fully grasp things and am trying to slowly build up a program.
Oh I forgot to better clarify, when I say the same sequence I mean for example it generates 232, 2, 188 for the first set and then 175, 6, 229 for the second set. It will then generate that same set of numbers every single time I either reupload the code, restart the Arduino, or whatever.
Thank you!
void setup() {
Serial.begin(9600);
}
void loop() {
int r1 = random(0, 255);
Serial.println(r1);
Serial.println(r2(r1));
Serial.println(r3(r2(r1)));
delay(5000);
}
int r2(int x) {
if(x >= 128){
int c2 = random(0, 128);
} else{
int c2 = random(128, 255);
}
}
int r3(int y) {
if(y >= 128){
int c3 = random(0,128);
} else{
int c3 = random(128, 255);
}
}