# How do I Compare two random values as 'either'?

Get help using Construct 2

### » Wed Oct 11, 2017 1:53 am

How can I ask the code if the numbers it returned with 'random(100)' are 'either(1, 2, 3, 4 or 5)'?

Here is what I want:

System - Random(100) Equal to | either(1, 2, 3, 4, or 5)

I understand there's no 'either' expression but that's what I'm asking. What expression is used in place of 'either' to get the result I want? And if there isn't one, how can I write my code to get the desired result? My brain is fried trying to figure this out!
B
28
S
11
G
1
Posts: 163
Reputation: 2,880

### » Wed Oct 11, 2017 2:10 am

Store the random result to a local variable (local=int(random(100)), and use it to test the result. If the values are actually 1 to 5, just add two conditions for local >= 1 AND local <= 5. Other wise you need to check each value , but in an OR block instead of an AND block.
B
71
S
22
G
273
Posts: 3,822
Reputation: 150,787

### » Wed Oct 11, 2017 2:21 am

To add to the previous comment.

If numbers are sequential as in your example, you can use "System -> Is between values -> floor(random(100)) between 1 and 5"

There are also a few workarounds to optimize it. For example, you can do this:
Compare two values-> find ("#1#2#3#9#15#" , "#" & floor(random(100)) & "#") >= 0

Or install the SwitchCase plugin:
viewtopic.php?t=64458&start=0
It's a really useful plugin and I'm using it a lot in my game.

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
125
Posts: 1,734
Reputation: 66,789