# Move to certain position dependant on randomizer

What I am trying to do, for my first project, I am trying to have a servo point to “Yes” or “No” written on a piece of paper. I have it randomized from 10-180, and if it is in the range of 10-95, I want it to move to 10 and if it is in the range of 96-180, I want it to move all the way to 180. I want to use a, "if pos=10-95, pos=10, else pos=180. please help.
pos=random(10,180);
myservo.write(pos);
delay(3500);
if (pos=10,95) true, pos=(10);
else pos=(180);
myservo.write(pos);
Also, whenever I run the program I always get the same results from each random. is there a way to prevnt this?

A simpler way is probably like this

``````if(pos < 96) {
myServo.write(10);
}
else {
myServo.write(180);
}
``````

If you want to check for a range then it must be done like this

``````if(pos > 10 and pos < 96) {
``````

…R

Some automatic engine-driven generator sets are equipped with an automatic exerciser [My Lowes Life](http://My Lowes Life)

cur5ry:
Some automatic engine-driven generator sets are equipped with an automatic exerciser

This makes no sense in the context of this Thread.

...R

`if (pos=10,95)`Always use "==" to test for equality. See above for testing a range of values.

The European style of real number values, e.g. '10,95' is not compatible with C. You have to use a period, e.g. '10.95'.

aarg:
The European style of real number values, e.g. '10,95' is not compatible with C. You have to use a period, e.g. '10.95'.

I think the OP wants to check if pos is in the range 10 to 95

...R

Robin2:
I think the OP wants to check if pos is in the range 10 to 95

...R

Oh, I see... probably got the idea from the random() parameter list above it.