Making Three Random Numbers Generate

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);
  }
}

See randomSeed() - Arduino Reference

For an Arduino Uno, you can use all analog inputs A0 up to A5 (inclusive).
See my example millis_reaction_timer.ino.
There could be a sensor at A0 keeping the input at 0V or 5V. If all analog inputs are used, then there is more chance that there will be random noise in the result.

Can you be more precise when you mention the limits of the random number ?

A number between 0 and 255 is from 1 (inclusive) up to 254 (inclusive).
When you do random(0, 255) then the number is from 0 (inclusive) up to 254 (inclusive).

To get a number from 0 (inclusive) up to 255 (inclusive) you need: random(0, 256).

The upper bound of the random() function is exclusive as you can read here: random() - Arduino Reference.

Koepel:
For an Arduino Uno, you can use all analog inputs A0 up to A5 (inclusive).

You can also use A6 and A7 for an analogRead() on an UNO, the circuitry is present on the chip, but is left unconnected because of the limited number of pins on the package. Not uncommon to see these used in generating a random seed since they are floating inputs.