How to pick a random bundle from the output

Hello, I’ve got an airtable module with the following Formula:

AND(
  OR(
    {url_last_posted} = BLANK(),
    IS_BEFORE({url_last_posted}, DATEADD(TODAY(), -1, 'days'))
  ),
  {Remaining} > 0
)

Output limit 1.

Example output with no output limit in place:

[
    {
        "URL": "https://url.com/1",
        "url_last_posted": "2024-06-25",
        "id": "rec666LP",
        "createdTime": "2024-06-19T14:24:26.000Z",
        "__IMTLENGTH__": 6,
        "__IMTINDEX__": 1
    },
    {
        "URL": "https://url.com/2",
        "url_last_posted": "2024-06-25",
        "id": "recJeJhBNy",
        "createdTime": "2024-06-04T07:30:19.000Z",
        "__IMTLENGTH__": 6,
        "__IMTINDEX__": 2
    },
    {
        "URL": "https://url.com/3",
        "url_last_posted": "2024-06-25",
        "id": "recKiL2SGJ",
        "createdTime": "2024-06-08T12:12:18.000Z",
        "__IMTLENGTH__": 6,
        "__IMTINDEX__": 3
    },
    {
        "URL": "https://url.com/4",
        "id": "recNpSvQqlp",
        "createdTime": "2024-06-26T07:43:37.000Z",
        "__IMTLENGTH__": 6,
        "__IMTINDEX__": 4
    },
    {
        "URL": "https://url.com/5",
        "url_last_posted": "2024-06-25",
        "id": "recRP16",
        "createdTime": "2024-05-20T12:03:18.000Z",
        "__IMTLENGTH__": 6,
        "__IMTINDEX__": 5
    },
    {
        "URL": "https://url.com/6",
        "url_last_posted": "2024-06-25",
        "id": "recVCBprss",
        "createdTime": "2024-06-12T17:25:35.000Z",
        "__IMTLENGTH__": 6,
        "__IMTINDEX__": 6
    }
]

Purpose:
this is part of my social media shcheduler/poster

What I am trying to achieve:
I would like to pick 1 bundle at random out of all possible ‘candidates’. Right now it outputs the same list in order each time, what’s the best way to grab 1 random bundle which meets my airtable rules?

Hi you can use this blue print.
blueprint (9).json (11.2 KB)

But use the max image length buy using array aggregator

the set variable use the round and random functions and multiply by max image length

random give you a random number between 0 and 1 then I multiply by max length to get a number between 0 and your max then use round to get the whole number

Then make sure it is not 0

Then iterate on the array we created and filter for the bundle you want

Then you can do whatever you want with that random bundle.

I’m sure you can optimize and get rid of the aggregator and array but the basic logic is there use what you want.

2 Likes

Let me know if you need further explaining.

Hi, thank you! This gives me some ideas, I was hoping to avoid using filters as it’s already in use for other purposes (i.e. posting in a certain category based on url contains)

That’s fine if you are using other filters this one will just filter for the random bundle that you want. Doesn’t mean you cannot use it for what you are using now