Sequence of primes by trial division

You are encouraged to solve this task according to the task description, using any language you may know.
Task

Generate a sequence of primes by means of trial division.



Trial division is an algorithm where a candidate number is tested for being a prime by trying to divide it by other numbers.

You may use primes, or any numbers of your choosing, as long as the result is indeed a sequence of primes.

The sequence may be bounded (i.e. up to some limit), unbounded, starting from the start (i.e. 2) or above some given value.

Organize your function as you wish, in particular, it might resemble a filtering operation, or a sieving operation.

If you want to use a ready-made is_prime function, use one from the Primality by trial division page (i.e., add yours there if it isn't there already).



Related tasks

   count in factors
   prime decomposition
   factors of an integer
   Sieve of Eratosthenes
   primality by trial division
   factors of a Mersenne number
   trial factoring of a Mersenne number
   partition an integer X into N primes


 
 
#May 10th., 2018.
 
Set Error Capture [On]
Allow User Abort [Off]
# Set default number of minutes
Set Variable [$maxduration; Value:1]
# Ask user for a desired duration of the test
Show Custom Dialog [	"Setup"; 
			"Enter the number of minutes (0,1-15, 6s increments) you would like this test to run.¶" & 
			"Hit any of the modifier-keys until the result-dialog appears, when you wish to break off the test."; 
			$maxduration ]
If [Get ( LastMessageChoice ) = 1]
	# Set all start-variables
	Set Variable 	[
			$result; 
			Value:	Let ( [ 
					$start = Get ( CurrentTimeUTCMilliseconds ) ; 
					x = Ceiling ( Abs ( 10 * $maxduration ) ) / 10 ; 
					y = Case ( x < ,1 ; ,1 ; x > 15 ; 15 ; x ) ; 
					$time = y * 60000 ; // 1 minute = 60000 milliseconds
					$number = 1 ; 
					$primenumbers = 2 ; 
					$duration = "" 
				] ; 
					"" 
				)]
	Loop
		# Increase each iteration by 2 (besides 2 there are no even prime numbers)
		# exit after duration is exceeded or when a modifier-key is actuated
		Exit Loop If [	Let ( [ 
					$number = $number + 2 ; 
					$i = 1
				] ; 
					$duration > $time or 
					Get ( ActiveModifierKeys ) ≥ 1  
				)]
		Loop
			# Loop until it is determined that a number is or isn't a prime number or the duration is exceeded
			# supplement $primenumbers each time one is found, update $duration each iteration
			Exit Loop If [	Let ( [ 
						$x = GetValue ( $primenumbers ; ValueCount ( $primenumbers ) - $i ) ; 
						$d = If ( $x > 0 ; $number / $x ) ; 
						$e = If ( Floor ( $d ) = $d ; $d ) ; 
						$i = $i + 1 ; 
						s = ( $x - 1 ) > $number/2 and $e = "" ; 
						$primenumbers = If ( 	$x = "" or s ; 
									List ( $primenumbers ; $number ) ; 
									$primenumbers ) ; 
						$duration = Get ( CurrentTimeUTCMilliseconds ) - $start
					] ; 
						$x = "" or $e > 0 or s or $duration > $time
					)]
		End Loop
	End Loop
	# Count the number of primes found
	Set Variable 	[
			$result; 
			Value:	Let ( [ 
					$n = ValueCount ( $primenumbers ) ; 
					$$array = $primenumbers
				] ; 
					"" 
				)]
	# Show results to user
	Show Custom Dialog [	"Result"; 
				List ( 
					"Prime numbers found: " & $n ; 
					"Largest prime number: " & GetValue ( $primenumbers ; 1 ) ; 
					"Duration of test (ms): " & $duration )]
End If
#
 