Post Reply 
(11C) Random Prime Number Generator
10-21-2018, 04:41 PM
Post: #7
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:

 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.

Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
(11C) Random Prime Number Generator - Gamo - 10-20-2018, 01:08 PM
RE: (11C) Random Prime Number Generator - Dieter - 10-21-2018 04:41 PM

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