Ruby_for_Dragons

An unofficial companion to the DragonRuby documentation

View on GitHub
Home DragonRuby API Documentation Quick Answers Kota’s Cheatsheet Sitemap

Code Blocks

Short, but powerful, drop-in code segments.

Gaussian Bell Curve

By Dee Schaedler

def gaussian(mean, stddev)
  theta = 2 * Math::PI * rand
  rho = Math.sqrt(-2 * Math.log(1 - rand))
  scale = stddev * rho
  [mean + scale * Math.cos(theta), mean + scale * Math.sin(theta)]
end

Random Integer in Range

By Dee Schaedler

def randr(min, max)
  rand(max - min + 1) + min
end