Skip to main content
Participant
July 18, 2021
Question

Random expression without repeating

  • July 18, 2021
  • 2 replies
  • 1196 views

I was looking for a solution to a problem. When I apply this expression

i = Math.round(random(1, 3)

It chooses a sequence of numbers with repetitions.. like...

1, 3, 2, 2, 2, 3, 1, 3, 3...

 

I'd like to know if there's a way to do the same thing without repeating numbers.

 

thanks!

This topic has been closed for replies.

2 replies

Mylenium
Legend
July 19, 2021

No need for complicated workarounds. Just increase the spread of the random range like e.g. from 1 to 300 and then scale the values with multiplications/ divisions or remap the ranges using linear(). Also random() accepts arrays, something which most people are completely ignorant of, so a simple random([1,2,3,2,3,1]) and so on can greatly improve distribution. In fact you could then even include a relatively trivial if()else{} check to prevent values on subsequent frames to be identical.

 

Mylenium

Roland Kahlenberg
Legend
July 19, 2021
Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV