Edit: random non crossing arrows
Here is a very simple solution (using a grid placement) with random colors, random lengths and random directions.

\documentclass[tikz]{standalone}
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\begin{document}
\begin{tikzpicture}
\fill[black] (0.5,0.5) rectangle (10.5,10.5);
\foreach \x in {1,...,10} {
\foreach \y in {1,...,10} {
% random HSB color definition
\pgfmathsetmacro\hue{rnd}
\definecolor{mycolor}{rgb:hsb}{\hue,1,1}
% random direction and length
\pgfmathsetmacro\angle{rnd*360}
\pgfmathsetmacro\halflen{rnd*.3+0.2}
% arrow
\draw[line width=2pt,-stealth,color=mycolor]
(\x,\y) +(\angle:-\halflen) -- +(\angle:\halflen);
}
}
\end{tikzpicture}
\end{document}
First version: random arrows
Here is a possible solution.
The rnd
function generates a pseudo-random number between 0 and 1. Thus:
(rnd*4+3,rnd*4+3)
gives a random coordinate between (3,3)
and (7,7)
.
++(rnd*360:rnd*2+1)
moves the previous coordinate in any direction (rnd*360
) with a length between 1cm and 3cm.
The random
function used with two arguments x and y generates a random integer between x and y. Thus:
\pgfmathtruncatemacro\numcolor{random(0,3)}
sets \numcolor
with a random integer between 0 and 3.
To change the seed used by pseudo-random generator at each compilation, you may use (with pdflatex
) \pgfmathsetseed{\pdfuniformdeviate 10000000}
in your peamble.

\documentclass[tikz]{standalone}
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\tikzset{
my arrow/.style={-latex,line width=2},
my arrow 0/.style={my arrow,color=red},
my arrow 1/.style={my arrow,color=violet},
my arrow 2/.style={my arrow,color=yellow},
my arrow 3/.style={my arrow,color=black},
}
\begin{document}
\begin{tikzpicture}
\filldraw[color=gray!50] (0,0) rectangle (10,10);
\foreach \num in {1,...,20} {
\pgfmathtruncatemacro\numcolor{random(0,3)}
\draw[my arrow \numcolor] (rnd*4+3,rnd*4+3) -- ++(rnd*360:rnd*2+1);
}
\end{tikzpicture}
\end{document}