home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / programm / 3098 < prev    next >
Encoding:
Internet Message Format  |  1992-11-10  |  1.6 KB

  1. Path: sparky!uunet!pipex!unipalm!uknet!root44!hrc63!mrcu!uk.co.gec-mrc!paj
  2. From: paj@uk.co.gec-mrc (Paul Johnson)
  3. Newsgroups: comp.programming
  4. Subject: Probabilistic Prime Numbers
  5. Message-ID: <2185@snap>
  6. Date: 10 Nov 92 17:07:33 GMT
  7. Sender: paj@uk.co.gec-mrc
  8. Reply-To: paj@uk.co.gec-mrc (Paul Johnson)
  9. Organization: GEC-Marconi Research Centre, Great Baddow, Essex
  10. Lines: 27
  11.  
  12. I am trying to write a small prime number generator using Algorithm P
  13. in Knuth.
  14.  
  15. Note for those without a copy of Knuth: this algorithm uses a randomly
  16. generated number to perform a primality test.  It can return one of
  17. two results: "Not prime" or "Probably prime".  If the latter, then the
  18. chance of error is < 0.25.  Repeated tests with different random
  19. numbers can reduce this probability very quickly.
  20.  
  21. I cannot understand the discussion of this test in Knuth, nor can I
  22. understand what his variables are.  Is `n' the number under test, or
  23. is it `q'?  If the former, why the statement "Let n = 1 + (2^k)q" just
  24. before the statement of Algorithm P.
  25.  
  26. What I would really like is some C or Pascal code which implements
  27. Algorithm P.  Failing that, a restatement with a more careful
  28. declaration of variables would be gratefully received.  Sedgwick and
  29. Numerical Recipies do not deal with primes.  Can anyone help?
  30.  
  31. Thanks in advance,
  32.  
  33. Paul.
  34.  
  35. Paul Johnson (paj@gec-mrc.co.uk).        | Tel: +44 245 73331 ext 3245
  36. --------------------------------------------+----------------------------------
  37. These ideas and others like them can be had | GEC-Marconi Research is not
  38. for $0.02 each from any reputable idealist. | responsible for my opinions
  39.