#!/usr/bin/env ruby
require("gsl")

N = 10000
rng1 = Rng.new(1)
rng2 = Rng.new(2)

hg = Histogram.new(100, [-4, 4])
hg2 = Histogram.new(100, [0, 6])
h2 = Histogram.new(100, [0, 10])
h3 = Histogram.new(100, [0, 4])

for i in 0...N do
  r1 = rng1.gaussian
  r2 = rng2.gaussian
  hg.increment(r1)
  hg2.increment(r1*r1)
  tmp = r1*r1 + r2*r2
  h2.increment(tmp)
  h3.increment(Math::sqrt(tmp))
end

hg.fprintf("gauss.hist", "%e", "%e")
hg2.fprintf("gauss2.hist", "%e", "%e")
h2.fprintf("gauss2d.hist", "%e", "%e")
h3.fprintf("rayleigh.hist", "%e", "%e")

#puts("Try gauss.gp")
system("gnuplot -persist gauss.gp")
File.delete("gauss.hist")
File.delete("gauss2.hist")
File.delete("gauss2d.hist")
File.delete("rayleigh.hist")
