Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- # coding: utf-8
- def normalrandom1
- 12.times.map{ Random.rand }.inject(:+) - 6
- end
- @switch = true
- @t = nil
- @s = nil
- def normalrandom2
- if @switch
- @switch = false
- @t = Math.sqrt(-2 * Math.log(1 - Random.rand))
- @u = 2 * Math::PI * Random.rand
- @t * Math.cos(@u)
- else
- @switch = true
- @t * Math.sin(@u)
- end
- end
- 100.times do
- a = normalrandom1 * 50 / 2 + 50
- a = (a < 0) ? 0 : a
- a = (a > 100) ? 100 : a
- print "#{a.floor} "
- end
- puts
- 100.times do
- a = normalrandom2 * 50 / 2 + 50
- a = (a < 0) ? 0 : a
- a = (a > 100) ? 100 : a
- print "#{a.floor} "
- end
- puts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement