开发者

CMWC (Complementary Multiply-with-carry) Matlab

开发者 https://www.devze.com 2023-03-10 10:27 出处:网络
To cite Mr. Marsaglia about generating more parameters for the CMWC 开发者_运维问答PRNG: \"Those wanting even more pairs r,a will need to find primes of the form p=ab^r+1 for which b=2^32-1 is a pr

To cite Mr. Marsaglia about generating more parameters for the CMWC 开发者_运维问答PRNG:

"Those wanting even more pairs r,a will need to find primes of the form p=ab^r+1 for which b=2^32-1 is a primitive root".

My question is in the method I should be using to do this. Especially with very large primes. This is what I've written in MATLAB:

isPrimitiveRoot = 0;
goodParameters = zeros(1,vectorSize);
nextFreeSpace = 1;
r = 1;
b = 2^32-1;
for a=0:2^32-1
  isPrimitiveRoot = 0;
  number = a*b^r+1;
  if(isprime(number))
    p = number;
    phi_p = p - 1;
    factors = factor(phi_p);
    isPrimitiveRoot = 1;
    for i=1:length(factors)
      if(isprime(factors(i)))
        if(mod(b^(phi_p/factors(i)),p)==1)
          isPrimitiveRoot = 0;
        end
      end
    end
  end
  if(isPrimitiveRoot)
    goodParameters(nextFreeSpace) = a;
    disp([nextFreeSpace a]);
    nextFreeSpace = nextFreeSpace + 1;
  end
end

I'm doing this because the steps to find good a parameters for a certain r lag are:

  1. Prove that p = a*b^r+1 is prime
  2. Prove that b is a primitive root of p. For that you need to evaluate the prime factors of p-1 and verify that b^((p-1)/p_i) =/= 1 (mod(p)) for all p_i prime factors of p-1.

Now it's pretty obvious why the script doesn't work. I've chosen b = 2^32 -1, and a lag r = 1 to keep it simple. But evaluating b^(phi_p/factors(i)) yields numbers simply too large (Inf).

  1. What should I be doing instead?
  2. Should I be using another software?
  3. Is there another algorithm for verifying primitive roots?


Well one could always use my vpi toolbox in matlab. While I did not provide a tool to explicitly generate/test for a primitive root, vpi does have the ability to work with arbitrarily large integers, as well as a powermod function to do much of the work.

I will point out however, that a simple, brute force loop over 2^32 elements will take a while to accomplish here, regardless of the tool.

0

精彩评论

暂无评论...
验证码 换一张
取 消