#### Howdy, Stranger!

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

# How to randomly select an integer from 2 sets of ranges?

edited July 2016

Hello! I'm very new to processing and I want to randomly select an integer out of 2 sets of ranges. For my example here, I'm working with colorMode(HSB) and I want the program to select Hue from say 0-50 and 200-255.

This is the code I have at the moment and as you can see, it is randomly selecting the hue value from 50-250 but is there any way I can set it so it selects from 0-50 and 200-250? So it doesn't select any number between 51-199 and 251-255.

Any advice or help would be greatly appreciated! Thank you!

``````int amt = 10;

int[] x1 = new int[amt];
int[] x2 = new int[amt];
int[] y1 = new int[amt];
int[] y2 = new int[amt];

color[] c = new color[amt];

color bgcolor;

void setup() {
size(600,600);
colorMode(HSB);
rectMode(CORNERS);
noStroke();
bgcolor = color(random(50),100,255);
background(bgcolor);

for(int i = 0; i < amt; i++){
x1[i] = int(random(width));
x2[i] = x1[i] + int(random(80,800));
y1[i] = int(random(height));
y2[i] = y1[i] + int(random(50,500));
c[i] = color(random(50,250),90,255);
}
}

void draw() {
for(int i = 0; i < amt; i++){
fill(c[i]);
rect(x1[i],y1[i], x2[i], y2[i]);
}
}
``````
Tagged:

• ``````if (random(100)>50)

0-50

else

200-255
``````
• `int rnd = (int) ( random(1) < .5? random(51) : random(200, 251) );`