#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# How to pick two numbers

edited March 2018

random(-4,4); i want to pick either -4 or 4 not inbetween

• edited March 2018

https://Processing.org/reference/conditional.html

``````int rnd = random(1) < .5? -4 : 4;
println(rnd);
exit();
``````
• if(random(100) < 50)

int rnd=-4;

else rnd=4;

• In your case, conceptually, some of the many options:

1. you can imagine multiplying 4 by a random (1 or -1),

2. more generally you can imagine testing a random (0-1) to see if it is above or below .5, then choose one of two numbers accordingly.

3. You could create a list of numbers and then choose one by shuffling.

The last approach is much more useful if you needed more than one choice and you need them to be unique, but it conceptually works like the sides of a coin or deck of cards: if you shuffle (4, -4) and then take the top number, it is one or the other.