Copy link to clipboard
Copied
Hi there!
I would like to generate a random number within a range of two numbers, but exclude one specific number.
Do you know a way to write it in the expression? For example: generate a number between 1 and 10, without 8.
Thanks !
Leo
There are a number of ways to approach it (depending mostly on exactly what you're after). Here are a couple of apporaches that will give you the numbers 1 through 10 without 8:
n = 8;
while (n == 8) n = Math.floor(random(1,11));
or
nums = [1,2,3,4,5,6,7,9,10];
idx = Math.floor(random(nums.length));
nums[idx]
Copy link to clipboard
Copied
There are a number of ways to approach it (depending mostly on exactly what you're after). Here are a couple of apporaches that will give you the numbers 1 through 10 without 8:
n = 8;
while (n == 8) n = Math.floor(random(1,11));
or
nums = [1,2,3,4,5,6,7,9,10];
idx = Math.floor(random(nums.length));
nums[idx]
Copy link to clipboard
Copied
thank you very much!