I'm creating an email which will be send automatically when a user is going to work for us. In this email i have an image placeholder. What i want is a random image showing in this image placeholder. Those "random" images are 12 pre-selected images. So to be clear it's just one image showing, not a carousel. Is this possible?

Thanks in advance.

3 Answers 3


Sure it can be done, there are a couple of ways to approach this.

Journey Builder method - requires setting up all different Emails prior. In the Journey you would be using the Random Split activity where you can define up to 10 different paths per activity, where the distribution then happens at random.

This method is probably the easiest as it requires no scripting. For statistical purposes this is would be a mess to deal with though.

AMPScript Random() method - requires using the Random() function to define a random integer between your number of variations (1 - 12) where, depending on the integer selected, a Dynamic Content piece is shown in the Email.

Essentially you set a variable to be an integer from Random() and depending on the integer set you can have AMPscript showing a different image content with simple IF condition set.

Code example:

VAR @random, @num1, @num2 
SET @num1 = 1 
SET @num2 = 2 
SET @random = random(@num1, @num2) 

%%[IF @random == "1" THEN ]%% 
%%[IF @random =="2" THEN ]%% 
  • Hi Rain, can you maybe be more specific and show some code which shows your example?
    – eazy4me
    Nov 16, 2018 at 12:42
  • Sure, added an example how to use the Random() and then show content based on the value.
    – Rain
    Nov 16, 2018 at 12:58
  • 3
    I would always set a default image as well. Even if it is just an ELSE statement, this way if something goes wrong, you have something there instead of just an empty space. I would also change it from IF / ENDIF to IF / ELSEIF / ENDIF to help reduce resource draw and increase processing speed. Nov 16, 2018 at 13:44
  • Good point Gortonington. Rain, I have more than 2 values for the random function. I got an error because random only supports a maximum of 2 parameters.
    – eazy4me
    Nov 16, 2018 at 13:50
  • wfrankhuizen - increase the @num2 parameter to equal 12. Now you'll get a random number between 1-12.
    – Rain
    Nov 16, 2018 at 14:00

So this is the code i have:

<img src="%%[ 
VAR @random, @num1, @num2 
SET @num1 = 1 
SET @num2 = 12 

SET @random = random(@num1, @num2) 
]%% %%[
%%[IF @random == "1" THEN ]%% 

%%[ELSEIF @random =="2" THEN ]%% 

%%[ELSEIF @random =="3" THEN ]%% 

%%[ELSEIF @random =="4" THEN ]%% 

%%[ELSEIF @random =="5" THEN ]%% 

%%[ELSEIF @random =="6" THEN ]%% 

%%[ELSEIF @random =="7" THEN ]%% 

%%[ELSEIF @random =="8" THEN ]%% 

%%[ELSEIF @random =="9" THEN ]%% 

%%[ELSEIF @random =="10" THEN ]%% 

%%[ELSEIF @random == "11" THEN ]%% 

%%[ELSEIF @random == "12" THEN ]%% 


What do i have to post in the img src"????"

  • Your code isn't quite correct here. This is to generate random number between 1-12. Check the PasteBin - pastebin.com/jLn20exU . To show image via URL method, wrap it in SRC tags like this: <img src="Your-Image-URL">
    – Rain
    Nov 16, 2018 at 15:26
  • I adjusted the code above but still no success..
    – eazy4me
    Nov 16, 2018 at 15:35
  • Here - full code. Enjoy: pastebin.com/veku5tDG
    – Rain
    Nov 16, 2018 at 15:40
  • I made a typo in my code. It works. Thanks for your help Rain!
    – eazy4me
    Nov 16, 2018 at 15:40

Use this code in your email.

%%[ VAR @random, @num1, @num2, @image 
SET @num1 = 1 
SET @num2 = 12 
SET @random = random(@num1, @num2) 
IF @random == "1" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/bc9aaf9b-7d0f-4ef1-a0d5-74189b5ff6ea.jpg?b=1523387048000" 
ELSEIF @random =="2" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/e52ececf-c3c3-4483-98d4-f92069121d20.jpg?b=1523387050000" 
ELSEIF @random =="3" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/c2d3d79a-dffb-4203-a41f-a02d4441a856.jpg?b=1523387050000" 
ELSEIF @random =="4" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/6c76fc15-1891-4d12-95c7-1dff7f7ff4db.jpg?b=1523387049000" 
ELSEIF @random =="5" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/21d67682-0127-4d3e-957f-aad8d9a2c382.jpg?b=1523387050000" 
ELSEIF @random =="6" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/f8cbacea-73e3-412e-aba9-6963633d9f69.jpg?b=1523387047000" 
ELSEIF @random =="7" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/f9ab44e3-a74a-4681-91fa-f81a62734234.jpg?b=1523387046000" 
ELSEIF @random =="8" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/1b488ad1-3cde-4bfb-a131-9658233b19ff.jpg?b=1523387048000" 
ELSEIF @random =="9" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/c92e8b4a-7784-4984-bd3f-0ee8d0755dcf.jpg?b=1523387049000" 
ELSEIF @random =="10" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/b9a31b5a-02c8-40e0-a23d-f488a8b188d3.jpg?b=1523387051000" 
ELSEIF @random == "11" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/530dba15-ec0c-4da7-a996-3289a883559b.jpg?b=1523387046000" 
ELSEIF @random == "12" THEN 
SET @image = "http://image.mailing.atlasprofessionals.com/lib/fe8413727c610d7f7c/m/1/89942a50-e82d-41e2-8ef0-feb49712adb2.jpg?b=1523387047000" 


<img src="%%=v(@image)=%%">

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .