Post Reply 
(11C) Random Prime Number Generator
10-21-2018, 08:45 AM
Post: #4
RE: (11C) Random Prime Number Generator
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.

Initialisation
Store the following numbers into these registers:

1: 31
2: 29
3: 23
4: 19
5: 17
6: 13
7: 11
8: 7


Code:
▸LBL A
 RAN#  8  ×  1  +  STO I
 RAN#  333  ×  INT  30  ×
 RCL (i)  +  STO 0
 CLx  STO 9
▸LBL 0
 8  STO I
▸LBL 1
 RCL 0
 RCL 9  RCL (i)  +
 ÷
 LSTx  x>y  GTO 2
 R↓  FRAC  x=0  GTO A
 DSE  GTO 1
 30  STO+ 9
 GTO 0
▸LBL 2
 RCL 0  RTN

Drawback: 2, 3 and 5 are never chosen.
Though I haven't tested I assume it runs faster.

Kind regards
Thomas
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 - Thomas Klemm - 10-21-2018 08:45 AM



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