'
' MRG.Create
'
' Initialize a multiple recursive RNG.
'
' SELF: {
'   lA:    List of coefficients
'   lX:    List of seeds, same size as lA
' }
'
' Returns: Object for MRG.GetNext
'
' Requires: Number.AsPoint, MRG.GetNext
'
' ArcView 3.2a
' 4 Jan 2002, WAH @QD
' (c) 2002 Quantitative Decisions
' All rights reserved.
'
' See http://crypto.mat.sbg.ac.at/results/karl/server/node7.html
'======================================================================'

lA = SELF.Get(0)
lX = SELF.Get(1)
'
' Allocation.
'

lPtA = {}
lPtX = {}
theMRG = {lPtA,lPtX}
'
' Convert to internal format.
'

for each a in lA
  lPtA.Add(av.Run("Number.AsPoint",a))
end
for each x in lX
  lPtX.Add(av.Run("Number.AsPoint",x))
end
'
' Run the MRG beyond the seeds.
'

for each i in 0..lA.Count
  av.Run("MRG.GetNext",theMRG)
end
return theMRG
' end of script

'
' MRG.GetNext
'
' Initialize a multiple recursive RNG.
'
' SELF:
'   llMRG:    Object created by MRG.Create
'
' Returns: Number in range 0..2^31-1
'
' Requires: Point.Add, Point.Multiply, Number.AsPoint, Point.AsNumber
'
' ArcView 3.2a
' 4 Jan 2002, WAH @QD
' (c) 2002 Quantitative Decisions
' All rights reserved.
'
' See http://crypto.mat.sbg.ac.at/results/karl/server/node7.html
'======================================================================'

llMRG = SELF
lPtA = llMRG.Get(0)  ' Coefficients
lPtX = llMRG.Get(1)  ' Last values
'
' Compute the inner product.
'

ptN = 0@0
for each i in 0..(lPtA.Count-1)
  ptA = lPtA.Get(i)
  if (ptA<>(0@0)) then
    ptN = ptN+av.Run("Point.Multiply",{ptA,lPtX.Get(i)})
  end
end
n = av.Run("Point.AsNumber",ptN)
ptN = av.Run("Number.AsPoint",n)
'
' Shift.
'

lPtX.Insert(ptN)
lPtX.Remove(lPtX.Count-1)
return n
' end of script