random delay on servo

Hi, Ive spent some time looking for a example on how to set a random delay on a servo

by this i mean to still have the 180 degree sweep (not random)

I would like to be able to have the servo travel to 180 and back to zero straight away at random times with a adjustable variable so like set min delay 500ms and max delay 5000ms

Any help would be greatly appreciated

At the start of the sweep you will use random() to determine the sweep duration and set a timestamp variable to the value of millis(). Next you just need to calculate the necessary interval between calling Servo.writeMicroseconds(1) so that the sweep will be completed over the given duration. Use File > Examples > 02.Digital > BlinkWithoutDelay as a model for how to do this in a non-blocking manner.

Hi found the solution thanks to: justPassingThru

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 180) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(100);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 180) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(100);                       // waits 15ms for the servo to reach the position
  }
  
 delay(random(500, 5000));      // adds random delay between (min,max)
}

was the simple delay before loop close at bottom