
I think the picture give the general idea and also i fell like i can smell the solution but definitely can't grasp it... I think that the counter may help me because i guess it allow to increment by one each time the ifthenelse find one candidate. Any help would be appreciated.
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{xifthen}
\begin{document}
\begin{tikzpicture}
\tikzstyle{titmarg}=[yshift=4cm]
\tikzstyle{textmarg}=[yshift=-5cm]
\tikzstyle{questmarg}=[yshift=-6cm]
\tikzstyle{descmarg}=[xshift=0cm,yshift=3.5cm]
\tikzstyle{lefmarg}=[xshift=-1.5cm]
\tikzstyle{rigmarg}=[xshift=1.5cm]
\newcommand*{\margine}{4}%
\newcommand*{\scala}{.1}%
\newcommand*{\prove}{200}%
\newcommand*{\side}{1.5}%
%\newcommand*{\checkzero}{0};
%\newcommand*{\checkuno}{0};
\pgfmathsetmacro{\scaleside}{\side*.1}%
\path[] (-\scaleside,-\scaleside) rectangle (\scaleside,\scaleside);
\shadedraw[thick,inner color=white,outer color=red!10] (-\side,-\side) rectangle (\side, \side) node [midway] (centro) {};
\node at (centro) [above,titmarg,draw,scale=2] {\textbf{Area hit and miss}};
\node at (centro) [above,textmarg,text width=9cm] {I want to approximate $\pi$ with $\frac{{\color{green}\# \text{hit}}}{{\color{green}\# \text{hit}}+{\color{red}\# \text{miss}}}$ as $N\to\infty$, where $N={\color{green}\# \text{hit}}+{\color{red}\# \text{miss}}$.};
\node at (centro) [above,questmarg] {What is the correct using of \emph{pgfmathaddtocount} or similar inside a \emph{foreach} cycle?};
\node at (centro) [descmarg,draw,fill=yellow!50] {$N=\prove$ trials};
\shade[inner color=white,outer color=green!20] (0,0) circle (1);
\foreach \k in {0,...,\prove}
{
\pgfmathsetmacro{\x}{\side*rand}%
\pgfmathsetmacro{\y}{\side*rand}%
\pgfmathsetmacro{\distance}{sqrt(\x*\x+\y*\y)}%
\ifthenelse{1 > \distance}
{
\shade[inner color=green,outer color=white] (\x,\y) {} circle (2pt);
%\pgfmathaddtocount{\the\checkuno}{1}
}
{
\shade[inner color=red,outer color=white] (\x,\y) {} circle (2pt);
%\pgfmathaddtocount{\the\checkzero}{1}
}
\fill[] (\x,\y) {} circle (.1pt);
}
%\draw[] (0,0) circle (1);
%
\end{tikzpicture}
\end{document}


\pgfmathaddtocount(I have never used it before) is not working, but if you include\usepackage{amsmath}(for the\textmacro), declare the counters as\newcounter{checkzero}an\newcounter{checkuno}(note: no backslash), and simply use\stepcounter{checkuno}and\stepcounter{checkzero}the incrementing functionality should work. – Peter Grill Sep 29 '14 at 22:01