非常感谢!!可是……能不能帮看下原题呀,主要是编个函数:
Function name: SHIFT
Inputs: a vector of size 7 (numbers)
Outputs: A random number.
How?
Shift Register generators are an example of a random number generator. The steps of the method are as follows:
i) Choose a binary seed. seed=(1,0,0,1,1,0,1)
ii) Shift the seed to the right 2 bits. seed=(0,0,1,0,0,1,1)
iii) Perform an exclusive-or addition of lines i and ii. seed=(1,0,1,1,1,1,0)
iv) Shift the sum to the left 3 bits. seed=(1,1,1,0,0,0,0)
v) Perform an exclusive-or addition of lines iii and iv. seed=(0,1,0,1,1,1,0)
vi) The answer is: 0*2^0+1*2+0*2^2+1*2^4+1*2^5+0*2^6=58
Your code should look like:
SHIFT=function(seed)
{
...lines of code...
return(_something to output_)
}
SHIFT=(c(0,1,1,0,1,1,0))