# Letting variables take on random values in TikZ inside \foreach [duplicate]

I want to use variables to store a value in TikZ and do computations based on it. For instance, I want to have variables a,b and c for the following purpose in TikZ:

\draw (a,b) circle (r)

I should be able to assign a,b and c (these can be decimals) and the circle must be drawn at the desired location with the desired radius.

How do I go about doing this?

PS: Essentially, I want to draw 100 small circles inside a unit square at random locations. Hence, I want the variables a, b and c to take random values. Below is my attempt, which doesn't work.

\documentclass{standalone}

\usepackage[first=0, last=1000]{lcg}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\foreach \i in {1,2,...,100}{
\def{a}{\rand\arabic{rand}}
\def{b}{\rand\arabic{rand}}
\draw(a/1000,b/1000) circle (0.001);
}
\end{tikzpicture}

\end{document}


## marked as duplicate by jub0bs, John Wickerson, user1876, bloodworks, WernerMay 29 '13 at 5:27

• Try \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \def\a{2} \def\b{3.5} \def\r{1} \draw (\a,\b) circle (\r); \end{tikzpicture} \end{document} – jub0bs May 29 '13 at 4:11
• How about just \def\a{...} and so on? And then \draw (\a,\b) circle (\r);. – John Wickerson May 29 '13 at 4:11
• @Jubobs Snap :-) – John Wickerson May 29 '13 at 4:12