class CompositeRng
A class of random number generators that work by nesting other PRNGs.
Constants
- CHURNS
The limits on the churn limit.
- INITS
The limits on the init.
- VERSION
The
CompositeRng
version.
Attributes
churn_limit[R]
The current upper limit on churn
Public Class Methods
new(parent, child, churn_limit=16, init=0)
click to toggle source
Create a composite PRNG
Parameters
-
parent - the starting PRNG
-
child - the progeny PRNG
-
churn_limit
- the max amount of churning done. -
init = the number of initial churn steps.
# File lib/composite_rng.rb, line 21 def initialize(parent, child, churn_limit=16, init=0) @parent, @child, @churn_limit = parent, child, churn_limit #Validate the churn_limit unless CHURNS === @churn_limit fail "Invalid churn limit #{@churn_limit}. Allowed values are #{CHURNS}" end #Validate the init unless INITS === init fail "Invalid init value #{init}. Allowed values are #{INITS}" end init.times { churn } end
Public Instance Methods
churn()
click to toggle source
Stir the soup!
Returns
-
a churned random number generator.
# File lib/composite_rng.rb, line 49 def churn (1 + @parent.rand(@churn_limit)).times {@child.rand(256)} @child end
rand(max=0)
click to toggle source
An access point for random numbers.
Parameters
-
max - the range of the numbers to be created.
Returns
-
a random value generated according to the max parameter.
# File lib/composite_rng.rb, line 42 def rand(max=0) churn.rand(max) end