
October 21st, 2012, 02:59 PM
|
 |
Contributing User
|
|
|
|
your j and k need not be terribly large,
and if j>k then the LFG needs j initial values.
And, you need only store j values.
In c a circular list is to me the obvious data structure to use. Here's an example using a queue.
Code:
k is 1
j is 5
The binary operation is addition. Many binary operations are ok, the choice affects sequence length and quality of the pseudo-random numbers.
modulus 10
n is 8
0 1 2 3 4 5 6 7 add list[n-1] to list[n-5] and append the sum mod 10
(7 + 3) mod 10 is 0. Append the sum and
discard the first element in the list
1 2 3 4 5 6 7 0
(4+0)%10 gives 4
2 3 4 5 6 7 0 4
(4+5)%10 gives 9
3 4 5 6 7 0 4 9
etceteras gives LFG pseudo-random numbers
7 0 4 9 5 2 2 6 5 0 2 4 0 5 5 7 1 1 6 1 8 9 0 6 7 5 4 4 0 7...
4 5 6 7 0 4 9 5
5 6 7 0 4 9 5 2
6 7 0 4 9 5 2 2
7 0 4 9 5 2 2 6
0 4 9 5 2 2 6 5
4 9 5 2 2 6 5 0
9 5 2 2 6 5 0 2
5 2 2 6 5 0 2 4
2 2 6 5 0 2 4 0
2 6 5 0 2 4 0 5
6 5 0 2 4 0 5 5
5 0 2 4 0 5 5 7
0 2 4 0 5 5 7 1
2 4 0 5 5 7 1 1
4 0 5 5 7 1 1 6
0 5 5 7 1 1 6 1
5 5 7 1 1 6 1 8
5 7 1 1 6 1 8 9
7 1 1 6 1 8 9 0
1 1 6 1 8 9 0 6
1 6 1 8 9 0 6 7
6 1 8 9 0 6 7 5
1 8 9 0 6 7 5 4
8 9 0 6 7 5 4 4
9 0 6 7 5 4 4 0
0 6 7 5 4 4 0 7
__________________
[code] Code tags[/code] are essential for python code!
|