How can a randomly picked background colour be chosen for each beamer frame?


This question is asked to round out the question Randomly assign color to background in the PDF whenever page is turned which asks for a solution which alters the colour when the pdf is displayed. On contrast the present question deals with randomly assigning colours during compilation.

2 Answers 2


Here is one way of doing this in ConTeXt. To set the color of a page, we need:

\definebackgrounds[page][background=color, backgroundcolor=...name...]

At each page, the setups specified in definebackgrounds are re-evaluated. So, to change the color of each page, we can simply change the value of the background color to a random color. It is easier to do so in Lua. So, here is a complete example:

  local random = math.random
  local format = string.format
  commands.change_color = function()
    options = { format("r=%0.3f, g=%0.3f, b=%0.3f", random(), random(), random()) }
    context.definecolor( {"randomcolor"}, options)

\startsetups change:color


% Just to visualize the result




which gives enter image description here



\pgfmathsetseed{\number\pdfrandomseed} % seed for random generator

\setbeamertemplate{background canvas}{%


    \foreach \n in {1,...,100}{


enter image description here

  • 1
    Just for curiosity, how did you compose the image?
    – Ignasi
    Commented Sep 5, 2014 at 12:12
  • 2
    The image is just a screenshot of the resulting pdf opened with Preview. No magic :) Commented Sep 5, 2014 at 12:14

You must log in to answer this question.

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