random.ps - Some useful random-number stuff in PostScript


 (/home/wherever/ps/lib/random.ps) run
 % to send it to a printer see include_run . . .

 /mean 43.2 def  /stddev 8.5 def
 {  ...
    mean stddev grand   % gaussian random
    ...  i n gt { exit } if
 } loop

 n irand  % random integer 0 .. n-1

 [ an array ] randomget   % random element


This module implements in PostScript a few simple procedures for using random numbers.


mean standarddeviation grand

This example leaves on the stack, a number from a Gaussian (or Normal) random distribution with the given mean and standard deviation.   Thus, the density is     f(x) = exp(.5 * x**2) / sqrt(2 * pi)

It uses the algorithm by Richard P. Brent (1973), Computer Centre, ANU, Canberra, published (1981) as CACM Algorithm 448

n irand

This example leaves on the stack an integer from 0 to n-1

[ an array ] randomget

This example gets a random element from the given array.
For example, the following executes one of the given procedures at random:
    [ /bassclef /trebleclef /sharp /natural ] randomget cvx exec


To install: go to www.pjb.com.au/comp/free/random.ps.txt and save the file to your local disc.
Rename it to random.ps and move it into some appropriate directory such as ~/ps/lib . . .

Or, first change directory to where you keep your PostScript libraries:
    cd /home/wherever/ps/lib/
(or wherever)   and then either:
    wget -O random.ps http://www.pjb.com.au/comp/free/random.ps.txt
    curl http://www.pjb.com.au/comp/free/random.ps.txt -o random.ps

Or, get it from github:
    git clone https://github.com/peterbillam/postscriptlib


Peter J Billam www.pjb.com.au/comp/contact.html


 20160501 first released version


Back to P J B Computing or to www.pjb.com.au . . .