Skip to content

Instantly share code, notes, and snippets.

@sj26
Created November 3, 2011 02:22
Show Gist options
  • Save sj26/1335604 to your computer and use it in GitHub Desktop.
Save sj26/1335604 to your computer and use it in GitHub Desktop.
def psuedorandoms seed
Enumerator.new do |yielder|
loop do
seed = Digest::MD5.digest(seed)
seed.unpack("Q*").each do |number|
yielder.yield number.to_f / 2**64
end
end
end
end
random = psuedorandoms "bob@example.com"
random.next
# => 0.7001791074933145
random.next
# => 0.23889280018014822
random.next
# => 0.7562936345272123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment