Drawing percolation configuration with TikZ

Okay here is a starting point for you. Actually drawing the hexagons is not complicated, you just can use the shapes.geometric library of tikz. Instead of \ifthenelse I found it easier to use an \ifnum statement to implement the conditional treatment. You have to be a little careful with the number of nodes you`re using to not exceed the capacity of Tex. Probably playing with the size of nodes or switching to LuaLatex could help.

enter image description here

Code:

\documentclass[border=1cm]{standalone}    
\usepackage{tikz}    
\usetikzlibrary{shapes.geometric}       
\begin{document}    
\begin{tikzpicture}[every node/.style={regular polygon, regular polygon sides=6, minimum size=1cm}]      
    \foreach \y [count=\yi] in {1,2,...,90}{
        \foreach \x in {0,1.5,...,45}{
            \pgfmathrandominteger{\a}{1}{100}
            \ifnum\a>50 
                \node[draw=white, fill=gray] at ({\x + mod(\yi,2)*0.75},{\y*sqrt(3)/4}) {};
            \else
                \node[draw=white, fill=gray!25] at ({\x + mod(\yi,2)*0.75},{\y*sqrt(3)/4}) {};
            \fi
        }
    }
\end{tikzpicture}
\end{document}

Edit:

Rendering the image with LuaLaTex helps in overcoming the memory limitations. The following picture is drawn with ymax=360 and xmax=180:

enter image description here

Edit 2

Okay here is some code for your bond percolation problem.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
%
\begin{document}
\begin{tikzpicture}[every path/.style={ultra thick, black}]
    %
    \coordinate (xa) at ({-1cm-0.8pt},0); % correcting the vectors for half the line width (0.8pt) of ultra thick
    \coordinate (ya) at (0,{-1cm-0.8pt});
    \coordinate (xb) at (0.8pt,0);
    \coordinate (yb) at (0,0.8pt);
    %
    \foreach \y in {1,2,...,50}{
        \foreach \x in {1,2,...,50}{
            \ifnum\x>1
                \pgfmathrandominteger{\a}{1}{100}
                \ifnum\a>50 
                    \draw ($(\x,\y)+(xa)$) -- ($(\x,\y)+(xb)$);
                \fi
            \fi
            %
            \ifnum\y>1
                \pgfmathrandominteger{\a}{1}{100}
                \ifnum\a>50 
                    \draw ($(\x,\y)+(ya)$) -- ($(\x,\y)+(yb)$);
                \fi
            \fi
        }
    }
\end{tikzpicture}%
%
\end{document}

enter image description here