Randomizer

Randomizer node can be very helpful if anybody wants to randomize the group of nodes.

Use Case:

  • Randomize 2 Different HTTP Request nodes.

image

I know this can be done using Functions and IF Node. But this will make the platform more no-code and faster.

Yes, can see how that can be useful for none technical people.

Anyway, till it got implemented there is actually just an IF-Node needed:

{
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": 50,
              "operation": "larger",
              "value2": "={{parseInt(Math.random()*100)}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        468,
        331
      ]
    }
  ],
  "connections": {}
}
1 Like

Any ETA for this?

Sadly not as there are currently a lot of more pressing things on our To-do list. Also esp. because it is already possible without to much work.

1 Like

No Problem @jan

Can we set random like this using the IF node?

Sadly impossible to answer. Yes and no. Depends on what you have set on the IF-Node and what you want to happen.

If you have an IF-Node like the one I created above and in 50% of the cases you want that people get 3 photos and in 50% of the cases that they get 2 photos then “yes”.

1 Like

Well, here is an example use case.

I want to send different image/message to user whoever triggering the bot.

I feel here Randomizer will help or Spintax will get the things done.

If you implement the Spintax Functionality, It’ll change the whole game and take it to next level. Please consider.

Something similar to Spintax can be done like this (not as easy and fancy but at least works for now):

{{['a','b','c','d'][Math.floor(Math.random()*4)]}}

Just replace the values in the array (the a,b,…) and the 4 (which is the number of items in the array). It will then always return a different string.

If you want to send different images then something like the above could help. If there are a lot of different ones to choose from it would however be best to do it in a Function-Node.

1 Like

This returns an Error

ERROR: No data got returned. Always return an Array of items!

What I posted above is an expression (can be recognized by {{ }}). So you can only paste that in a parameter that you have set to be an expression.

If you want to use a Function-Node it would more look like this:

const values = [
  'a',
  'b',
  'c',
  'd',
];

items[0].json.myVariable = values[Math.floor(Math.random()*values.length)];
return items;
1 Like

Works Great. Thanks @jan