class RSpec::Core::Ordering::Random
Orders items randomly.
@private
def initialize(configuration)
def initialize(configuration) @configuration = configuration @used = false end
def jenkins_hash_digest(string)
implemented in C) but has the advantage of not requiring us
It's a bit slower than MD5 (primarily because `Digest::MD5` is
Jenkins provides a good distribution and is simpler than MD5.
http://en.wikipedia.org/wiki/Jenkins_hash_function
def jenkins_hash_digest(string) hash = 0 string.each_byte do |byte| hash += byte hash &= MAX_32_BIT hash += ((hash << 10) & MAX_32_BIT) hash &= MAX_32_BIT hash ^= hash >> 6 end hash += ((hash << 3) & MAX_32_BIT) hash &= MAX_32_BIT hash ^= hash >> 11 hash += ((hash << 15) & MAX_32_BIT) hash &= MAX_32_BIT hash end
def order(items)
def order(items) @used = true seed = @configuration.seed.to_s items.sort_by { |item| jenkins_hash_digest(seed + item.id) } end
def used?
def used? @used end