# How to define a random number with xcolor and tikz/pgf

I tried to get a random color with xcolor and tikz:

\documentclass{article}
\usepackage[xetex, rgb]{xcolor}
\usepackage{tikz}

\begin{document}

\pgfmathsetseed{1}
\begin{tikzpicture}
\xdefinecolor{MyColor}{hsb}{rand, 1.0, 1.0}
\node[fill=MyColor]{Hello};
\end{tikzpicture}
\end{document}


But this does not work, it reports the following error

Missing number, treated as zero


Does anybody know how to get random colors? thanks.

-

\begin{tikzpicture}
\pgfmathparse{rnd}
\xdefinecolor{MyColor}{hsb}{\pgfmathresult, 1.0, 1.0}
\node[fill=MyColor]{Hello};
\end{tikzpicture}

-

The egre solution gives you a Pseudorandom color.

If you use pdftex or one of his son, I suggest you this solution, where for every compilation you will obtain a different color.

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\pgfmathparse{rnd}
\xdefinecolor{MyColor}{rgb}{\pgfmathresult, 1.0, 1.0}
\node[fill=MyColor](A) at (0,0){Hello};

\edef\R{\pdfuniformdeviate 255}
\edef\G{\pdfuniformdeviate 255}
\edef\B{\pdfuniformdeviate 255}
\xdefinecolor{MyColor2}{RGB}{\R,\G,\B}
\node[fill=MyColor2](A2) at (0,-.5){Hello};
\end{tikzpicture}
\end{document}

-