title: Generating random points then connecting points less than certain distance away
body: <p>I currently have the code below which produces the later output. I would like to generate the 10 points randomly as I already am. But instead of having blue dashed lines connecting to the the location (0,0), I want them to connect to the other dots if the distance is less than 4cm away.</p>
  <p>I attempted things such as storing the data into arrays but updating and accessing the values was not working. I attempted nested for loops but handling the seed became difficult. What is a good way to do this?</p>
  <pre><code>\documentclass{standalone}
  
  \usepackage{tikz}
  
  \begin{document}
  \begin{tikzpicture}
  
  \draw[step=0.5cm,color=gray] (-2.5,-2.5) grid (2.5,2.5);
  
    
  \pgfmathsetseed{2}
  \foreach \x in {1,...,10}
  {
    \pgfmathrandominteger{\a}{-240}{240}
    \pgfmathrandominteger{\b}{-240}{240}
    \fill [color=red,anchor=center](\a*0.01,\b*0.01) circle (0.1);
    
    % CHANGE HERE
    \draw [color=blue,densely dotted] (\a*0.01,\b*0.01) -- (0.0,0.0);
  };
  
  \end{tikzpicture}
  \end{document}
  </code></pre>
  <p><a href="https://i.stack.imgur.com/FZsYZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FZsYZ.png" alt="10x10 grid with randomly placed filled dots and dashed lines connecting to 0,0" /></a></p>