class Hashrander
Public Class Methods
new(hash)
click to toggle source
Generate random numbers of arbitrary size from a hash
# File lib/tiledenticon.rb, line 47 def initialize hash @hash_i = 0 @hash = hash end
Public Instance Methods
get_rand(sample_size, max)
click to toggle source
# File lib/tiledenticon.rb, line 52 def get_rand sample_size, max i1 = @hash_i % @hash.length hash_str = @hash[i1, sample_size] # Check if wrap over length rem = i1 + sample_size - @hash.length if rem > 0 hash_str << @hash[0, rem] end @hash_i += sample_size max * hash_str.hex/(16**sample_size) end