i tried using millis. however the servo is not moving randomly after a gap of 2 seconds
int iOldPos, iNewPos = 0;
long previousMillis = 0;
const int interval = 20;
void setup() {
myservo.attach(3);
}
void loop(){
iNewPos = random(200, 800);
iOldPos = random(800, 2400);
unsigned long currentMillis = millis();
if(iOldPos != iNewPos && currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
iOldPos = iNewPos;
myservo.write(iNewPos);
}
}