(11C) Random Prime Number Generator
10-21-2018, 04:41 PM
Post: #7
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: (11C) Random Prime Number Generator
(10-21-2018 08:45 AM)Thomas Klemm Wrote:  We can restrict the search to numbers that aren't divisible by 2, 3 or 5.
Thus we only choose numbers of the sequence: 7, 11, 13, 17, 19, 23, 29, 31, …
On the other hand we only use these numbers to check if the chosen random number is divisible.

Good idea. But the program does not do what it is supposed to. ;-)

(10-21-2018 08:45 AM)Thomas Klemm Wrote:  Drawback: 2, 3 and 5 are never chosen.

That's not a problem: The goal is generating prime numbers with four digits, i.e. somewhere between 1000 and 9999.

This means that the progam has to be modified. First a random integer between 33 and 332 has to be be chosen, this is multiplied by 30 and finally one of the primes in R1...R8 is added. This returns a "prime candidate" between 997 and 9991. Since 997 is prime this is a possible result outside of the desired range. The only way to correct this seems to be a simple test whether R0 is less than 1000. Or even less than 1009 which is the first prime in this range. ;-)

This means the program would start like this:

Code:
▸LBL A  RAN#  8  ×  1  +  STO I  RAN#  300  ×  INT  33 + 30  ×  RCL (i)  +  STO 0 ...

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. Thus the largest prime candidate is 10021. Replacing the constant 300 with something like 299,999 sbould fix this.

Dieter
 « 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)