# Random dots excluding certain values or range of values

I am able to generate the random dots, but how would I exclude specific values or range of values? For example, excluding 8 or excluding 10-20.

    \begin{pgfpicture}
\foreach \x in {1,...,1000}{
\pgfmathrandominteger{\a}{1}{100}
\pgfmathrandominteger{\b}{1}{100}
\pgfpathcircle{\pgfpoint{+\a pt}{+\b pt}}{+1pt}
\color{blue!40!white} \pgfsetstrokecolor{blue!80!black}
\pgfusepath{stroke, fill}
}
\end{pgfpicture}


The range 10 to 20 can be excluded using \ifnum commands:

\documentclass{article}
\usepackage{pgf}
\usepackage{pgffor}
\newif\ifok
\begin{document}
\begin{pgfpicture}
\pgfsetfillcolor{blue!40!white}
\pgfsetstrokecolor{blue!80!black}
\foreach \x in {1,...,1000}{
\oktrue
\pgfmathrandominteger{\a}{1}{100}
\ifnum\a>9 \ifnum\a<21 \okfalse \fi\fi
\ifok
\pgfmathrandominteger{\b}{1}{100}
\ifnum\b>9 \ifnum\b<21 \okfalse\fi\fi
\ifok
\pgfpathcircle{\pgfpoint{+\a pt}{+\b pt}}{+1pt}
\pgfusepath{stroke, fill}
\fi
\fi
}
\end{pgfpicture}
\end{document}


BTW, the color settings are constant and are moved outside the loop.

The following variant keeps the number of samples constant, but generates only 89 distinct values for \a and \b and adjusts the output of the random processor to leave the gap of eleven values between 10 and 20:

\documentclass{article}
\usepackage{pgf}
\usepackage{pgffor}
\begin{document}
\begin{pgfpicture}
\pgfsetfillcolor{blue!40!white}
\pgfsetstrokecolor{blue!80!black}
\foreach \x in {1,...,1000}{
\pgfmathrandominteger{\a}{1}{89}
\pgfmathrandominteger{\b}{1}{89}
\ifnum\a>9
\pgfmathtruncatemacro\a{\a+11}
\fi
\ifnum\b>9
\pgfmathtruncatemacro\b{\b+11}
\fi
\pgfpathcircle{\pgfpoint{+\a pt}{+\b pt}}{+1pt}
\pgfusepath{stroke, fill}
}
\end{pgfpicture}
\end{document}


You can use the powerful expl3 conditionals:

\documentclass{article}
\usepackage{pgf}
\usepackage{pgffor}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\exclude}{mm}
{
\tl_set:Nn \l_eightsaregreat_exclude_tl { \c_false_bool }
\clist_map_inline:nn { #1 }
{
\tl_put_right:Nn \l_eightsaregreat_exclude_tl
{
|| \int_compare_p:n { ##1 }
}
}
\bool_if:VF \l_eightsaregreat_exclude_tl { #2 }
}
\tl_new:N \l_eightsaregreat_exclude_tl
\cs_generate_variant:Nn \bool_if:nF { V }
\ExplSyntaxOff

\begin{document}

\begin{pgfpicture}
\pgfsetfillcolor{blue!40!white}
\pgfsetstrokecolor{blue!80!black}
\foreach \x in {1,...,1000}{
\pgfmathrandominteger{\a}{1}{100}
\pgfmathrandominteger{\b}{1}{100}
\exclude{\a=8, 10 <= \a <= 20,\b<5, 30 <= \b <= 50}
{
\pgfpathcircle{\pgfpoint{+\a pt}{+\b pt}}{+1pt}
\pgfusepath{stroke, fill}
}
}
\end{pgfpicture}
\end{document}


The conditions are concatenated as “or”, with a false condition for keeping the balance, and the code is executed only if the conditions turns out to be false.