0

This question already has an answer here:

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, Werner May 29 '13 at 5:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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
  • 1
    @Jubobs Snap :-) – John Wickerson May 29 '13 at 4:12
  • @Jubobs I have updated my question and is slightly different from the duplicate one. – user1876 May 29 '13 at 4:20
  • @Jubobs I think this question answers it. Thanks – user1876 May 29 '13 at 4:30