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:

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.

3 Likes

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;
2 Likes

Works Great. Thanks @jan

Hi @jan !

I use

{{['a', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', 
  'A', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z',
  '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'][Math.floor(Math.random()*62)]+['a', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', 
  'A', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z',
  '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'][Math.floor(Math.random()*62)]}}

This is the result of the work:

I understand that the function does not always cope and works correctly. What can be done about it?

Thank you!

I think I found the mistake - 62. It’s not 62 characters. Several letters of the alphabet are lost, so there’s less than 62.

This version of the code seems to work:

{{['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'][Math.floor(Math.random()*62)]+['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'][Math.floor(Math.random()*62)]+['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'][Math.floor(Math.random()*62)]}}

Problem solved. :+1:

1 Like

Can anyone give me information about randomizer how it works?

Finally, made this community node. :heart:

4 Likes

This knot seems very interesting.

Is only 2 options possible?

1 Like

Hi @Alberto_Julio

For now yes. Maybe using multiple randomizer nodes will help?

I’m not sure we can control the number of outputs dynamically through options in the visual editor.

cc: @Jon

1 Like