tikz beamer add tag
topnush
At https://tex.stackexchange.com/questions/560993/how-to-show-rows-of-randomly-colored-circles I asked how to show random colored circles.The answer is not complete yet as I really want to be able to limit the number of different colors from which the random selection can be made. But in fact I also have another related question. Take that code as the starting point:

\documentclass{beamer}

\setbeamersize{text margin left=10mm,text margin right=5mm}
\setbeamertemplate{frametitle}[default][center]
\usepackage{tikz}

\newcommand{\randomcolor}{%
\pgfmathsetmacro{\R}{random(0,10000)/10000}%
\pgfmathsetmacro{\G}{random(0,10000)/10000}%
\pgfmathsetmacro{\B}{random(0,10000)/10000}%
\definecolor{randomcolor}{rgb}{\R,\G,\B}%
}

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

\begin{document}

\begin{frame}{The counting problem}

\foreach \j in {1,2,...,5} {\foreach \i in {1,2,...,10} {\tikzcircle{.05\textwidth}}\\}

\end{frame}
\end{document}

I would like the next frame to have the same set of circles set out in the same way but this time in sorted order.
That is all circles of the same color should be next to each. This doesn't make sense of course unless we can also restrict the number of different colors.


user 3.14159
Here is a proposal. With \RandomColors you can set the number of random colors, and define them. If you switch on \recordingtrue the number of times a specific color gets used gets recorded. In order to show the summary, you then want to switch it off with \recordingfalse. One could make the code more "fancy" with \makeatletter and perhaps even expl3, but I decided to keep it basic.


\documentclass{beamer}
\setbeamersize{text margin left=10mm,text margin right=5mm}
\setbeamertemplate{frametitle}[default][center]
\usepackage{tikz}
\newcommand\RandomColors[2][]{\edef\itmp{1}%
\edef\anushNC{#2}%
\loop
\pgfmathsetmacro{\R}{random(0,10000)/10000}%
\pgfmathsetmacro{\G}{random(0,10000)/10000}%
\pgfmathsetmacro{\B}{random(0,10000)/10000}%
\definecolor{randomcolor-\itmp}{rgb}{\R,\G,\B}%
\expandafter\edef\csname anushnum\itmp\endcsname{0}%
\edef\itmp{\the\numexpr\itmp+1}%
\ifnum\itmp<\the\numexpr#2+1\repeat
}

\RandomColors{10}
\newif\ifrecording
\newcommand{\tikzcircle}[1][]{%
\pgfmathtruncatemacro{\myrnd}{random(1,\anushNC)}%
\ifrecording
\expandafter\xdef\csname anushnum\myrnd\endcsname{\the\numexpr1+\csname anushnum\myrnd\endcsname}%
\fi
\begin{tikzpicture}[baseline=-0.5ex]
\end{tikzpicture}}%

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

\begin{document}

\begin{frame}[t]
\frametitle{The counting problem}
\recordingtrue
\foreach \j in {1,...,5} {\foreach \i in {1,...,10} {%
\tikzcircle}\\}
\recordingfalse
\end{frame}

\begin{frame}[t]
\frametitle{The counting problem}
\foreach \j in {1,...,\anushNC} {%
\edef\ic{\csname anushnum\j\endcsname}%
\foreach \i in {1,...,\ic}{\tikzcircle[fill=randomcolor-\j]}\\}
\end{frame}
\end{document}

![ani.gif](/image?hash=b211e80b10222d26c5f4b471af73e576ba5fa3256dccd7f3aadc3d89a991bd80)
samcarter
To get a limited set of colours which are as distinguishable as possible, one could define a series of colours which are equidistant in hsb space. From these colours one can then select a random one:


\documentclass{beamer}
\setbeamersize{text margin left=10mm,text margin right=5mm}
\setbeamertemplate{frametitle}[default][center]
\usepackage{tikz}

\newcommand{\tikzcircle}[2][red]{\tikz[baseline=-0.5ex]{\fill[{#1},radius=#2] (0,0) circle ;}\hspace{0pt}}%

\def\numcolors{6}
\def\numdots{100}

\pgfmathparse{1/\numcolors}%
\definecolorseries{foo}{hsb}{step}{red!90!black}{\pgfmathresult,0,0}
\resetcolorseries[\numcolors]{foo}%

\newcounter{bar}
\foreach \x in {1,...,\numcolors}{
\setcounter{bar}{\x}
\newcounter{mycount\alph{bar}}
}

\pgfmathsetseed{\number\pdfrandomseed}

\begin{document}
\begin{frame}{The counting problem}
\foreach \x in {1,...,\numdots}{%
\pgfmathrandominteger{\myran}{1}{\numcolors}%
\setcounter{bar}{\myran}%
\tikzcircle[{foo!![\myran]}]{8pt}%
}%
\end{frame}

\begin{frame}{The counting problem}
\foreach \x in {1,...,\numcolors}{%
\setcounter{bar}{\x}%
\foreach \y in {1,...,\csname themycount\alph{bar}\endcsname}{%
\tikzcircle[{foo!![\x]}]{8pt}%
}%
}
\end{frame}

\end{document}


![document.gif](/image?hash=2c5c9ebac10ba758424619ecdb9989874ebf2350660e095db1a410eefef4c544)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.