How to create range ? on: 3 x28BYJ-48 steppers random moves with AccelStepper.h

Hello

I modified this code in order to make the steppers moove randomly but it looks like it additionate or something and get out of a range I would like to keep them in.

Range would be

minpos = 0
maxpos = 280

How could I achieve this ?
Sounds easy to my feelings but my brain is more like hitting a wall.

#include <AccelStepper.h>

#define MotorInterfaceType 8
// Define two steppers and the pins they will use
AccelStepper stepper3 = AccelStepper(MotorInterfaceType, 8, 10, 9, 11);
AccelStepper stepper2 = AccelStepper(MotorInterfaceType, 4, 6, 5, 7);
AccelStepper stepper = AccelStepper(MotorInterfaceType, 0, 2, 1, 3);


int pos1 = 20; // this I dont know what it does change, just a starting pos ? 
int pos2 = 20;
int pos3 = 20;

void setup()
{ 
  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(600);
  stepper2.setMaxSpeed(1000);
  stepper2.setAcceleration(600);
  stepper3.setMaxSpeed(1000);
  stepper3.setAcceleration(600);

}

void loop()
{
  if (stepper.distanceToGo() == 0)
  {
     pos1 = -(pos1+random(-26, 26)); // Original was "pos1 = -pos1;"
    stepper.moveTo(pos1);
  }
  if (stepper2.distanceToGo() == 0)
  {
    pos2 = -(pos2+random(-26, 26)); // Same
    stepper2.moveTo(pos2);
  }
    if (stepper3.distanceToGo() == 0)
  {
     pos3 = -(pos3+random(-26, 26)); // Same
    stepper3.moveTo(pos3);
  }
  stepper.run();
  stepper2.run();
  stepper3.run();
}

You may want to constrain those values.

Add something like this

if (pos1 > maxPos) {
   pos1 = maxPos;
}
if (pos1 < minPos) {
  pos1 = minPos;
}

…R