(11C) Random Prime Number Generator
10-21-2018, 07:02 PM (This post was last modified: 10-21-2018 07:54 PM by Albert Chan.)
Post: #10
 Albert Chan Senior Member Posts: 1,896 Joined: Jul 2018
RE: (11C) Random Prime Number Generator
(10-21-2018 05:20 PM)Dieter Wrote:
(10-21-2018 01:31 PM)Albert Chan Wrote:  Update: without prime table, a simple way is keep picking random number until it is prime.
I think Klemm prime-wheel code do this ...

Sure, this also is the idea behind Gamo's original program. Generate an odd random integer (here within the wrong range, though) and check if it's prime. If not, try another one.

My mistake. I was thrown by Gamo code "LBL3 2 STO+0"
I thought it re-use the random number by searching forward ...

(10-21-2018 04:41 PM)Dieter Wrote:  There is another point where the program may not work as intended. The random number can be as large as 0,99999 99999. Multiplying this by 300 with 10-digit precision returns 300 exactly.

Just curious, is it a guess, or does RAN# really get that high ?

FYI, if above were done with binary math, it will not happen.
Example, for IEEE double, 1 ULP below 1.0 = 1 - 1/2^53

Assumed N >= 0, max(N RAN#) = N - N/2^53

If N is pow-of-2, above is exact (no rounding), thus less than N

If N is not pow-of-2, N/2^53 is slightly bigger than 1/2 ULP, thus rounded-up

So, with binary math, max(N RAN#) = N - 1 ULP < N
 « Next Oldest | Next Newest »

 Messages In This Thread (11C) Random Prime Number Generator - Gamo - 10-20-2018, 01:08 PM RE: (11C) Random Prime Number Generator - Dieter - 10-20-2018, 07:08 PM RE: (11C) Random Prime Number Generator - Gamo - 10-21-2018, 03:22 AM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 05:09 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-21-2018, 08:45 AM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 04:41 PM RE: (11C) Random Prime Number Generator - Albert Chan - 10-21-2018, 01:31 PM RE: (11C) Random Prime Number Generator - John Keith - 10-21-2018, 01:52 PM RE: (11C) Random Prime Number Generator - Dieter - 10-22-2018, 11:03 AM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 05:20 PM RE: (11C) Random Prime Number Generator - Albert Chan - 10-21-2018 07:02 PM RE: (11C) Random Prime Number Generator - Albert Chan - 10-22-2018, 01:02 AM RE: (11C) Random Prime Number Generator - Gene - 10-21-2018, 07:47 PM RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018, 09:09 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-21-2018, 08:47 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-21-2018, 09:03 PM RE: (11C) Random Prime Number Generator - Gene - 10-21-2018, 10:02 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 03:46 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 04:10 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 09:11 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 09:22 AM RE: (11C) Random Prime Number Generator - Gamo - 10-22-2018, 10:32 AM RE: (11C) Random Prime Number Generator - Dieter - 10-22-2018, 11:23 AM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 12:28 PM RE: (11C) Random Prime Number Generator - Thomas Klemm - 10-22-2018, 12:31 PM RE: (11C) Random Prime Number Generator - Dieter - 10-22-2018, 06:43 PM

User(s) browsing this thread: 1 Guest(s)