This question is similar to this question tikz: Distribute evenly and randomly circles (which is also where I got some of the code for this TiKz picture) but is different. I wish to draw multiple circles that do not overlap but some of these circles are different. Currently this is my code:
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\newcommand{\fillrandomly}[5]{
\xdef\xlist{4}
\xdef\ylist{4}
\pgfmathsetmacro\diametersqr{(#3*2)^2}
\foreach \i in {1,...,#4}{
\foreach \k in {1,...,20}{
\pgfmathsetmacro\x{rnd*#1}
\pgfmathsetmacro\y{rnd*#2}
\xdef\collision{0}
\foreach \element [count=\i] in \xlist{
\pgfmathtruncatemacro\j{\i-1}
\pgfmathsetmacro\checkdistancesqr{ ( ({\xlist}[\j]-(\x))^2 + ({\ylist}[\j]-(\y))^2 ) }
\ifdim\checkdistancesqr pt<\diametersqr pt
\xdef\collision{1}
\breakforeach
\fi
}
\ifnum\collision=0
\xdef\xlist{\xlist,\x}
\xdef\ylist{\ylist,\y}
\draw (\x,\y) circle [radius=#3] node[anchor=center] {#5};
\breakforeach
\fi
}
}
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{scope}[xshift=0.2cm,yshift=0.2cm]
\fillrandomly{3.6}{3.8}{0.15}{12}{$-$}
\fillrandomly{3.6}{3.8}{0.15}{12}{$+$}
\end{scope}
\draw (0,5) -- (0,1);
\draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
\draw (1,0) -- (3,0);
\draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
\draw (4,1) -- (4,5);
\draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
\draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
\draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
\node[anchor=center] at (2,-0.5) {concentrated strong acid};
\begin{scope}[xshift=5cm]
\foreach \X in {1,...,3}
{\draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] {$+$};
\draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] {$-$};}
\draw (0,5) -- (0,1);
\draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
\draw (1,0) -- (3,0);
\draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
\draw (4,1) -- (4,5);
\draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
\draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
\draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
\node[anchor=center] at (2,-0.5) {dilute strong acid};
\end{scope}
\begin{scope}[xshift=10cm]
\begin{scope}[xshift=0.2cm,yshift=0.2cm]
\fillrandomly{3.6}{3.8}{0.15}{8}{$-$}
\fillrandomly{3.6}{3.8}{0.15}{8}{$+$}
\end{scope}
\foreach \X in {1,...,8}
{
\draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
}
\draw (0,5) -- (0,1);
\draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
\draw (1,0) -- (3,0);
\draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
\draw (4,1) -- (4,5);
\draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
\draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
\draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
\node[anchor=center] at (2,-0.5) {concentrated weak acid};
\end{scope}
\begin{scope}[xshift=15cm]
\foreach \X in {1,...,2}
{\draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] {$+$};
\draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] {$-$};}
\draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
\draw (0,5) -- (0,1);
\draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
\draw (1,0) -- (3,0);
\draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
\draw (4,1) -- (4,5);
\draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
\draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
\draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
\node[anchor=center] at (2,-0.5) {dilute weak acid};
\end{scope}
\draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] {Unionised};
\draw (0,-1.5) circle (0.15) node[anchor=center] {$+$} node[right=0.1cm] {Positive Ion};
\draw (0,-2) circle (0.15) node[anchor=center] {$-$} node[right=0.1cm] {Negative Ion};
\end{tikzpicture}
\vspace{-2cm}
\caption{Concentrated and dilute solutions of weak and strong acids}
\end{figure}
\end{document}
Which produces this image:
I am unsure how to stop overlapping between the three different types of circles especially in the first and third beaker counting from the left. XeLaTeX answer please