Pyxplot

Examples - Random numbers


Prev
Next

Download this example:

Using Pyxplot's random number generator

.

Script

set multiplot
set nodisplay
set seed 0
width = 7

Nsamples = 500

rand() = random.random()

# Make a table of random numbers
set samp Nsamples
set output "temp.dat"
tabulate 1-2*rand():1-2*rand() using 0:2:3

# Draw a unit circle and a unit square
box from -width/2,-width/2 to width/2,width/2
circle at 0,0 radius width/2 with lt 2

# Now plot the positions of these random data points and count how many
# lie within a unit circle
n=0
foreach datum i,j in 'temp.dat' using 2:3
 {
  point at width/2*i , width/2*j with ps 0.1
  n = n + (hypot(i,j)<1)
 }

print "pi=%.4f"%(n / Nsamples * 4)

set output 'output.eps'
set display
refresh