I would like to do a Tikz image animation of growing lines with a certain randomness with regard to their initial rotation angle (and potentially also with a certain randomness in their initial x and y coordinates). I am aware that Tikz provides a rand and a random function (see example code) which work nicely for static images. However, inside of an animation they create a new random number for each frame. How could the random number be passed such that it is only evaluated initially?




\begin{animateinline}[autoplay, loop]{24}
        \foreach \x in {0,1,...,5}
        \draw [thick, rotate around={random*10:(\x,0)}] ({\x},0) -- ++(0,\ry);
        \path [use as bounding box] (0,0) rectangle (5,2.1);


Example animation obtained with code above

  • Have you tried to set a seed? \pgfmathsetseed{<integer>}: Explicitly sets the seed for the pseudo-random number generator (see pgf manual).
    – Unknown
    May 14, 2022 at 13:53
  • Thank you very much! It works if the \pgfmathseed{} command is inserted within the multiframe environment.
    – LeonC
    May 14, 2022 at 14:05
  • I added a answer based on my comment. Please accept it, when it solved your problem.
    – Unknown
    May 14, 2022 at 14:12

1 Answer 1


To solve this problem one can set a seed with:


Description from the PGF/TikZ-Manual: Explicitly sets the seed for the pseudo-random number generator. By default it is set to the value of \time×\year.

You must log in to answer this question.

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