3

I have a problem. I have a graph, and I must paste a random number in every vertex of this graph. Vertices have coordinates.

A part of code :

\foreach \pos/\name in {{(0,0)/a}, {(1,-1)/b}, {(1.5,-2)/c},
                                {(1.3,-2.5)/d}, {(0.6,-2.5)/e}, {(2,-2.66)/f}, 
                                {(1.3,-3.5)/g},{(0.6,-3.5)/h},{(2,-3.33)/i},
                                {(1.9,-1.3)/j}}
            \node[circle,fill=black!25,minimum size=15pt,inner sep=0pt] (\name) at \pos {\pgfmathsetmacro{rand}};
Andrew Swann
  • 95,762
  • It's really hard to understand what you mean. Do you want to draw a bicycle? Ared the "some coordinates" also random or are they defined? It would be really helpful if you could provide us with something that you already tried, and ask for specific questions on your example. – Habi Nov 18 '14 at 12:19
  • I guess by "cycle" you mean a "loop". I also guess you are using some drawing program. How you store coordinates will depend very much on which program you are using. Please post more information, preferably containing a small document with your set-up, cf. minimal working example (MWE) – Andrew Swann Nov 18 '14 at 12:36
  • ok, thanks for notes, I've added some information. – just a man Nov 18 '14 at 13:00

1 Answers1

4

Here is a solution:

\documentclass[tikz]{standalone}
\pgfmathsetseed{\pdfuniformdeviate 10000000} % new seed at each compilation
\begin{document}
\begin{tikzpicture}
  \foreach \pos/\name in {
    {(0,0)/a},
    {(1,-1)/b},
    {(1.5,-2)/c},
    {(1.3,-2.5)/d},
    {(0.6,-2.5)/e},
    {(2,-2.66)/f}, 
    {(1.3,-3.5)/g},
    {(0.6,-3.5)/h},
    {(2,-3.33)/i},
    {(1.9,-1.3)/j}%
  } {
    \pgfmathsetmacro\myvalue{abs(rand)}
    \pgfset{number format/.cd,fixed}
    \node[circle,fill=black!25,minimum size=15pt,inner sep=0pt,font=\tiny]
    (\name) at \pos {\pgfmathprintnumber{\myvalue}};
  }
\end{tikzpicture}
\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283