Random int with exclude
in
Programming Questions
•
1 year ago
Hi all,
I'll rephrase my post:
I need to call a function that returns a random int between an upper and lower limit but excludes value(s) inbetween?
This code from StackOverflow is apparenly a way of doing just that, but I am unsure how I would get this working in Processing as the random() function works differently?
If anyone can help that would be great...
If anyone can help that would be great...
Dave
public int getRandomWithExclusion(Random rnd, int start, int end, int... exclude) {
int random = start + rnd.nextInt(end - start + 1 - exclude.length);
for (int ex : exclude) {
if (random < ex) {
break;
}
random++;
}
return random;
}
Any help would be greatly appreciated
Thanks
Dave
1