Select random image from an image url

I have a simple scenario where OpenAI creates a post based on my prompt and publishes to a Google Business Profile. I want to randomly choose 1 of 20 images to insert into the profile post. i have the images hosted on my web server and can access them via their URL. How can I do this and which modules should I use? Also, is there a more efficient way to do this?

Thanks

1 Like

Hi Ray,

Sounds good, there are many different methods to pick a random image.

Could you maybe screenshot your output of those 20 images so I can grasp an idea of the data structure?

If it is an array of URLs, you could use shuffle() to randomise the array, and get(;1) to get the first item in the array.

My urls look like this:

Ahh I see:

So I would add a set variables for the below (replace the links with your urls, comma seperate each link)

What this does:

  1. Split() - Splits each link into an array
  2. Shuffle - Randomises the links in the array
  3. Get - Gets the first item in the random array

{{get(shuffle(split("link1,link2,link3,link4"; ",")); 1)}}

Map the variables into the file you are trying to upload.

This will give you a random URL out of your selection.

I added the variable array as you suggested and mapped to the “a” variable in my Google My Business module. I get an error. PS: The random array works because I can see different URLs when I click the variable in my GMB module. Di I do something wrong?


Got it working. I needed to choose photo and then as the variable as the source. Thank you very much for your help.

3 Likes