Is there a way to exclude numbers from the random expression?

New Here ,
Mar 31, 2022 Mar 31, 2022

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

TOPICS
Expressions , Scripting

Views

53

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Mar 31, 2022 Mar 31, 2022
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]

Likes

Translate

Translate
Adobe Community Professional ,
Mar 31, 2022 Mar 31, 2022

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]

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

LATEST

thank you very much!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines