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


 
comment
  Prime number generator in S-BASIC. Only odd numbers are 
  checked, and only the prime numbers previously found (up 
  to the square root of the number currently under examination) 
  are tested as divisors.  Memory is conserved by saving only the 
  first 50 primes as potential divisors, since that is sufficient 
  to test all numbers up to 32767, which is the highest integer 
  value supported by S-BASIC
end
 
$lines
 
$constant false = 0
$constant true = 0FFFFH
 
var i, k, m, n, s, nprimes, divisible = integer
dim integer p(50)
 
rem compute p mod q
function mod(p, q = integer) = integer
end = p - q * (p / q)
 
input "How many primes do you want to generate",nprimes
 
rem initialize p with first prime and display it
p(1) = 2
print using "##### "; p(1);
 
rem now check odd numbers until nprimes are found
i = 1   rem count of primes found so far
k = 1   rem index of largest prime <= sqrt of n
n = 3   rem current number being checked
while i < nprimes do
   begin
      s = p(k) * p(k)
      if s <= n then k = k + 1
      divisible = false
      m = 1   rem index into primes previously found
      while (m <= k) and (divisible = false) do
         begin
            if mod(n, p(m)) = 0 then divisible = true
            m = m + 1
         end
      if divisible = false then
         begin
            i = i + 1
            if i <= 50 then p(i) = n
            print using "##### ";n;
            if pos(0) > 60 then print   rem wrap long lines
         end
      n = n + 2
   end
print "All done. Goodbye"
end
 