# [pstricks] re-using the same random variable

jmpapy Jean-Michel.Papy at esat.kuleuven.ac.be
Fri Oct 8 17:49:12 CEST 2004

Quoting Herbert Voss <Herbert.Voss at alumni.TU-Berlin.DE>:

> jmpapy wrote:
> > Hello,
> >
> > Here are two problems:
> >
> > (1) How to use twice the same random variable at a time in the same
>
> > plot?
> > for instance in the following code:
> > ===============
> > \begin{pspicture}(-5,-0.2)(5,2)
> > \psline{-}(-5,0)(5,0)
> >
> \psplot[linecolor=red,plotpoints=200,showpoints=true,linestyle=none]
{-5}
> > {5}{rand 2147483647 div rand 2147483647 div 2.72 exp mul} %x.e^{x}
> > \end{pspicture}
>
>
> hm, I have some problems to really understand here. The
> variable x in general (xMax-xMin)/plotpoints ...

Maybe I don't understand how the postscript language works in this case.
To me, each time the program read "rand", it returns a new integer
randomly drawn from [0 2^31 -1]. Is it correct ?

>
> > (2) How to use twice the same random variable simultaneously in two
>
> > different plot ?
>
> \documentclass{article}
> \usepackage{pstricks}
>
> \begin{document}
>
> \begin{pspicture}(-5,-0.2)(5,2)
> \psaxes(0,0)(-5,0)(5,2)
> \psplot[linecolor=red,plotpoints=200,showpoints=true,linestyle=none]
{-5}
>      {5}{ rand 2147483647 div dup 2.72 exp mul } %x.e^{x}
> \end{pspicture}

I understand this piece of code. You use the duplication command in
order to have twice the same value. Well done, thanks !!

>
> \begin{pspicture}(-5,-0.2)(5,7)
>    \pstVerb{
>      rrand srand
>      rand 2147483647 div /randInt exch def
>    }
>    \psaxes(0,0)(-5,0)(5,6)
>    \psset{plotpoints=200,linestyle=dotted,linewidth=3pt}
>    \psplot[linecolor=red]{-5}{5}{ randInt 6 mul } % x
>    \psplot[linecolor=blue]{-5}{5}{ randInt 6 mul sqrt } % x2
> \end{pspicture}
>
> \end{document}
>

here I don't fully agree with this example. This code draws two straight
lines. It seems that the value of randInt is constant and therefore it
does not look as a random signal.is it possible that it changes for each
abscissa ?

JM
> I changed it only for the demo to sqrt(randInt)
>
> Herbert
>
>
>
> --
> http://TeXnik.de/
> http://PSTricks.de/
> ftp://ftp.dante.de/tex-archive/info/math/voss/Voss-Mathmode.pdf
> http://www.dante.de/faq/de-tex-faq/
> http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes
>
> _______________________________________________
> pstricks mailing list
> pstricks at tug.org
> http://tug.org/mailman/listinfo/pstricks
>