Please i dont want if inside if


I wand to add shortcut
That make this

It take random number between 1 to 1000
And than
If thae number is less than 100 it do it take url and open safari
If thae number is less than 200 it do it take other url and open safari
If thae number is less than 300 it do it take other url and open safari
If thae number is less than 400 it do it take other url and open safari
If thae number is less than 500 it do it take other url and open safari

Please i dont want if inside if

What you have written out looks just like it would in Shortcuts. You should just be able to drop the random number, if, URL and open URL actions in the order you have with the values you specify. As for if inside if, that may be the right way to do it, whether you want it to be or not. If it is a random lookup based requirement then try a dictionary.

Presumably you already tried doing this and encountered a problem. If so, perhaps it would make sense to share that and get guidance on what the issue is?

From an algorithm point of view, what I am wondering is:

  1. Why is the random number 1000 rather than say 10, which would look to give you an equivalent variation with fewer digits. The only obvious reason would be if you plan to add many more URLs.
  2. If your random number is one, would you expect all URLs to be opened? That is what it currently says. If that is the case, build a list of URLS (i.e. use add to variable in each IF), then at the end pass that variable to the Open URLS action.
  3. Do you really want nothing to happen just over half the time? That is what you currently have. Note that it is just over half because you are using random numbers up to 1000 and your final IF is a less than, rather than a less than or equal to.

Hope that helps.

A dictionary sounds like the way to do this. Add your items then choose a random item. Done and done. You don’t even have to generate the random number.

What i tring to do is
1 Learn to make if comant
With more than just 2 outcome

2 not to make if inside if
The same isuue hapan to me in exeal

If in Shortcuts is an if-else based construct, not an if-elseif-else based construct. What you seem to be asking for is not how it works. :man_shrugging:

I agree with @Ibutlr If you create a dictionary with the keys for your input and values for your output, you can then use the Get Dictionary Value to pass in a key such as a number and get back your URL for example. Much cleaner than a series of Nested IF statements and more flexible for adjusting in the future if you need to add additional key/value pairs.

A dictionary is one way of getting to what you need but it would be a pain to input a dictionary with 1000 keys.

There’s also a missing component to your problem where what will happen if the number is greater than 500?

A way to solve this is to range match 1-99,100-199, etc.

This shortcut accomplishes that with a some assumptions

  • another url will open if the number is greater than 500
  • The difference between ranges is 100

To be fair, it isn’t really range matching but rather doing some math to get the next multiple of 100 from the random number. Having that multiple decreases the size of the dictionary you have to create since you only have to think about the multiples 100,200,300…

Thnk you very much
You help me a lot

If i want that the dictionary will run 3 command
And not open url
How can i do it
Now if can replase mt 4 if with this dictionary and this is great
But it open url
Not run comand

@Guy1234, it would definitely be worth you telling us in as much detail as you can share, what you actually want to achieve in the end.

For example selection of actions vs. data is not necessarily equivalent.

Maybe using a dictionary of shortcut names and then passing the randomly selected result to the Run Shortcuts action is a good approach? Maybe it is still nested IFs? Maybe it is something else?

Without the full picture it is going to take a lot longer to guide you to the answer/solution.

I want to the Run Shortcuts action in the dictionary
How can i do it

You can’t, you can have the name of the shortcut as the value and then use it as a variable, but not the actual action.

As Sylumer said, unless you tell us the result you’re looking for it’s very hard to help.