(11C) Random Prime Number Generator

10212018, 04:41 PM
Post: #7




RE: (11C) Random Prime Number Generator
(10212018 08:45 AM)Thomas Klemm Wrote: We can restrict the search to numbers that aren't divisible by 2, 3 or 5. Good idea. But the program does not do what it is supposed to. ;) (10212018 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 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 10digit 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 »

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