Generate a random code of 8 numbers

Hi,

For a project I need to generate a code of 8 random numbers. I’m tying to do it with a math function but it’s not working. Little catch it cannot start with the sequence “12xxxxxx”

Thanks for your help

Hey @Maxkzn. You can generate a random 8-digit number using this
PS: It will never begin with the sequence “12xxxxx”

1 Like

Thank you so much :slight_smile: Is there a way to also remove the 0 of the possible number ?

Yes we can do that as well

just paste this

{{floor(random * 9) + 3}}{{floor(random * 9) + 3}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}
1 Like

Thanks but sometime it’s giving results with zero :thinking:

Try this @Maxkzn
{{floor(random * 7) + 3}}{{floor(random * 7) + 3}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}{{floor(random * 9) + 1}}

2 Likes

Seems good thank you so much

1 Like

You can do it this way too,

{{substring(join(shuffle(split(emptystring + 3456789 + emptystring + 3456789 + emptystring + 3456789; emptystring)); emptystring); 0; 8)}}

Module Export

You can copy and paste this module export into your scenario. This will paste the module with the above variables.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 48,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "random_number",
                        "scope": "roundtrip",
                        "value": "{{substring(join(shuffle(split(emptystring + 3456789 + emptystring + 3456789 + emptystring + 3456789; emptystring)); emptystring); 0; 8)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 894,
                            "y": -270,
                            "name": "8-digit rand excl. 012"
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "random_number",
                                "label": "random_number",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

5 Likes