Question: Part Four - Implementing the Acorn Generator Create a class called Acorn. Instance Variables: one or more instance variables representing the state ( think about
Part Four Implementing the Acorn Generator
Create a class called Acorn.
Instance Variables:
one or more instance variables representing the state think about how many you need
don't store extraneous values
Methods:
initself seed: listint M: int: constructor. Although
is often considered the seed and
are often considered the initial values, for programming ease, we'll lump them into a single list for the parameter where the first element is
and so on Ensure that seed is a list containing integers. If not, raise a TypeError. Verify that
; if not, raise a ValueError.
iterself: method that returns the iterator
nextself: method that returns next numbers in sequence. This should be a list of integers including
even though it will be the same Raises StopIteration exception when seuqence is repeating.
getstateself: function that returns the current state. The current state should be represented as a dictionary. This dictionary should have the following keys:
'vals' storing the list of integers representing the previous values
M storing the integervalued modulus
Note: you don't need this dictionary to contain anything that would be beneficial for determining the period if we reload the state, we'll assume it's starting from that point with no previous values
setstateself state: function that takes in dictionary representing the state in the same format returned by getState and sets appropriate instance variables. As mentioned above, calling this should reset the random number generator as if it has not seen previous values.
A sample sequence with
and a seed and values of :
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
