# pstricks-add: set seed for psRandom

The figure shown below contains "dots" scattered randomly using \psRandom from the pstricks-add package. I need the capability of regenerating the same pattern for several figures (and in time, gif animations). Moreover, I also want to find a seed that produces a "better" set of "dots".

I am using psRandom because I am new to pstricks and, apart from being able to select the seed, it has exactly the functionality I need. (I did have a look at the pstricks-add manual (from 2004) but it does not mention it as a possible option.)

Does anyone have a suggestion to how I can fix this? I imagine that the seed is set in a variable that I should be able to overwrite...

I am open to alternatives not involving psRandom. However, I am trying to move away from tikz and I am therefore looking for a solution using pstricks.

Thank you very much for your help. The tex file shown below will reproduce the figure.

% summary: Figure containing random dots...
%
%          execute the following commands sequentially in order to typeset.
%          $latex texput.tex %$ dvips texput.dvi
%          \$ ps2pdf texput.ps

\documentclass[pstricks]{standalone}

\begin{document}
%
\begin{pspicture}*(-5.5,-5.5)(7.5,5.5)
\def\myFrame{5cm}
\def\myWidth{8pt}
\def\myGreen{green!80!black}
\def\myMagenta{magenta}
\def\myCyan{cyan!90!black}
\def\myBlack{black!70!gray}
% Magenta dots
\psRandom[dotstyle=o, fillstyle=solid, fillcolor=\myMagenta,%
linecolor=\myGreen, randomPoints=20, dotsize=\myWidth]%
(-\myFrame,-\myFrame)%
( \myFrame, \myFrame)%
{\psframe[linecolor=black](-\myFrame,-\myFrame)(\myFrame,\myFrame)}
% Cyan dots
\psRandom[dotstyle=o,fillstyle=solid,fillcolor=\myCyan,linecolor=\myGreen,%
randomPoints=4,dotsize=\myWidth]%
(-\myFrame,-\myFrame)%
( \myFrame, \myFrame)%
{\psframe[linecolor=black](-\myFrame,-\myFrame)(\myFrame,\myFrame)}
% Black dots
\psRandom[dotstyle=o,fillstyle=solid,fillcolor=\myBlack,linecolor=\myBlack,%
randomPoints=2,dotsize=\myWidth]%
( 5,-5)%
( 7, 5)%
{\psframe[linecolor=black,linestyle=dashed]( 5, -5)( 7, 5)}
\end{pspicture}
%
\end{document}


The file pstricks-add.tex initialized the random number generator by the command

rrand srand


in the macro \psRandom@iii.

To make the result reproducible, we need to change rrand to any constant number, say, 42.

Put in the preamble of your document (after \usepackage{pstricks-add})

\makeatletter
\def\psRandom@iii(#1)(#2)#3{%
\def\pst@tempA{#3}%
\ifx\pst@tempA\pst@empty\psclip{\psframe(#2)}\else\psclip{#3}\fi
\pst@getcoor{#1}\pst@tempA
\pst@getcoor{#2}\pst@tempB
\begin@SpecialObj
\pst@tempA\space /yMin exch def
/xMin exch def
\pst@tempB\space /yMax exch def
/xMax exch def
/dy yMax yMin sub def
/dx xMax xMin sub def
42 srand                 % initializes the random generator
/getRandReal { rand 2147483647 div } def
\psk@dotsize % defines /DS ... def
\@nameuse{psds@\psk@dotstyle}
\psk@randomPoints {
\ifPst@color getRandReal getRandReal getRandReal setrgbcolor \fi

• I keep on being amazed of how much knowledge many of you have. May I suggest a couple of additions: Just after "makealetter" add the following two lines: \define@key[psset]{pstricks-add}{setSeed}[0]{\pst@checknum{#1}\psk@setSeed} and \psset[pstricks-add]{setSeed=0} Replace 42srand by: \psk@setSeed\space cvi dup 0 eq { pop rrand } if srand Now the seed can be set easily using: \psRandom[setSeed=42,...](xmin,ymin)(xmax,ymax){} – Sigve Karolius Mar 19 '15 at 14:06