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


 
class
	APPLICATION
 
create
	make
 
feature
 
	make
		do
			sequence (1, 27)
		end
 
	sequence (lower, upper: INTEGER)
			-- Sequence of primes from 'lower' to 'upper'.
		require
			lower_positive: lower > 0
			upper_positive: upper > 0
			lower_smaller: lower < upper
		local
			i: INTEGER
		do
			io.put_string ("Sequence of primes from " + lower.out + " up to " + upper.out + ".%N")
			i := lower
			if i \\ 2 = 0 then
				i := i + 1
			end
			from
			until
				i > upper
			loop
				if is_prime (i) then
					io.put_integer (i)
					io.put_new_line
				end
				i := i + 2
			end
		end
 
feature {NONE}
 
	is_prime (n: INTEGER): BOOLEAN
			-- Is 'n' a prime number?
		require
			positiv_input: n > 0
		local
			i: INTEGER
			max: REAL_64
			math: DOUBLE_MATH
		do
			create math
			if n = 2 then
				Result := True
			elseif n <= 1 or n \\ 2 = 0 then
				Result := False
			else
				Result := True
				max := math.sqrt (n)
				from
					i := 3
				until
					i > max
				loop
					if n \\ i = 0 then
						Result := False
					end
					i := i + 2
				end
			end
		end
 
end
 