Skip to content

Instantly share code, notes, and snippets.

@fritz0705
Created September 4, 2010 13:49
Show Gist options
  • Save fritz0705/565193 to your computer and use it in GitHub Desktop.
Save fritz0705/565193 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
if $*.length < 2
$stderr.puts "Usage: random.rb MIN_NUMBER MAX_NUMBER [QUALITY]"
exit
end
range = Range.new($*[0].to_i, $*[1].to_i)
quality = $*[2] != nil ? $*[2].to_i : 10
random_reader = File.new("/dev/urandom")
number = 0
until range === number || number > range.end
read = random_reader.read(quality)
i = quality
read.each_byte do |byte|
number += byte * i
i -= 1
end
end
puts number % range.end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment