Sha256: 3d4db00908f70997503d594f16a9209e6179c633b93c7d3cbf6c7012d9ca4745

Contents?: true

Size: 564 Bytes

Versions: 1

Compression:

Stored size: 564 Bytes

Contents

# frozen_string_literal: true

class ConsistentRandom
  class Context
    # @api private
    attr_reader :seeds

    # @param existing_context [Context, nil] Existing context to copy generators from
    def initialize(existing_context = nil)
      @seeds = (existing_context ? existing_context.seeds.dup : {})
    end

    # Return a random number generator for the given name and seed
    #
    # @param name [String] Name of the generator
    # @return [Random] Random number generator
    def seed(name)
      @seeds[name] ||= Random.new_seed
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
consistent_random-1.0.0 lib/consistent_random/context.rb