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...

enter image description here

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


% Magenta dots
\psRandom[dotstyle=o, fillstyle=solid, fillcolor=\myMagenta,%
linecolor=\myGreen, randomPoints=20, dotsize=\myWidth]%
( \myFrame, \myFrame)%
% Cyan dots
( \myFrame, \myFrame)%
% Black dots
( 5,-5)%
( 7, 5)%
{\psframe[linecolor=black,linestyle=dashed]( 5, -5)( 7, 5)}
| improve this question | | | | |

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})

    \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
    \psk@randomPoints {
     \ifPst@color getRandReal getRandReal getRandReal setrgbcolor \fi
     getRandReal dx mul xMin add
     getRandReal dy mul yMin add
     \ifx\psk@fillstyle\psfs@solid fill \fi stroke
    } repeat
| improve this answer | | | | |
  • 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
  • It is a good suggestion. Maybe you could send it to Herbert Voss who maintains pstricks-add – Boris Mar 19 '15 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.