## Adobe Support Community

• Is there a way to exclude numbers from the random ...

# 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

51

Likes

Report

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

## 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

2 Replies 2
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

Report

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

Copy link to clipboard

Copied

LATEST

thank you very much!

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources
Troubleshooting FAQs
After Effects Community Recap
Getting started with After Effects