Simple Randomizer with Function Node & IF Node

You can easily build a simple randomizer node using Functions Node & IF Node.

Function Node generate a random number between 0-6\

If the number is smaller than 3 It’ll be True else it will be false.

Number
0
1
2
3 This is the center number between 0-6
4
5
6

Workflow Code:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        350,
        350
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.RandomNumber = Math.floor(Math.random() * 7);\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        550,
        350
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$node[\"Function\"].json[\"RandomNumber\"]}}",
              "value2": 3
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        750,
        350
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        950,
        250
      ]
    },
    {
      "parameters": {},
      "name": "NoOp1",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        950,
        440
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Hey @mcnaveen!

Thank you for sharing this. Can you also share it on the workflows page? :slightly_smiling_face:

2 Likes

How can I do that bro?

If you haven’t, sign-up for the account, and you’ll see the option of Share New workflow. You can add a title, description as well as paste this workflow. :slightly_smiling_face:

1 Like

I’m not getting verification email. Could you please check? @jan

image

Did you check Spam folder, Promotions-Tab and searched for emails from “n8n”?

Yeah. Nothing arrived.