How can you compare 2 specific values from a single rand call?

I’m trying a sort an expression to compare two specific values from a single rand() call like this

(rand(0,3) == (0 || 2) ? 100 : 0)

but it doesn’t work. Is there a way to compare two specific values returned from a single rand() call?

(rand(0,3) == 0 || rand(0,3) == 2) ? 100 : 0

…isn’t any good as that then uses two rand() calls which could obviously, and probably will, return 2 different numbers.

Any one got any ideas please?

I’ve just thought of something, and will give it a try…

(rand(0,3) < 2 ? 100 : 0)

This is working for my needs, for now, by using 0 and 1 rather than 0 and 2. But if I actually need the values 0 and 2, it will fail. So, is there a way to check for 2 specific values from a rand() call?.

I do not think you can do this with a single rand call. You can have more conditions after another though, such as:

$rand(0,7)=0?TRUE:$$rand(0,7)=3?TRUE:$$rand(0,7)=6?TRUE:FALSE$

So if the result is 0, 3, or 6 the value is “TRUE”, if not “FALSE”

2 Likes