Created
November 13, 2009 00:43
-
-
Save perryqh/233465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# = srand_seed_generator.rb - Random seed generator uses the system time and currently running processes to generate a highly random seed. | |
# | |
# Perry Hertler mailto:[email protected] | |
# | |
# == Example | |
# | |
# my_seed = PwFoo::SrandSeedGenerator.new.get_next_seed | |
module PwFoo | |
require 'digest/md5' | |
class SrandSeedGenerator | |
def initialize | |
end | |
def get_next_seed | |
time_in_micro = Time.new().to_f * 100000 | |
checksum = _get_checksum | |
time_in_micro * time_in_micro + checksum.to_i | |
end | |
def _get_checksum | |
Digest::MD5.hexdigest(`ps axww | gzip`) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment