Here's a possible implementation of the generate_primes(limit) function using the Sieve of Eratosthenes algorithm:
```python
def generate_primes(limit):
# Create a boolean array "is_prime[0..limit]" and initialize
# all entries as true. A value in is_prime[i] will finally be
# false if i is Not a prime, else true.
is_prime = [True] * (limit + 1)
# 0 and 1 are not prime
is_prime[0] = is_prime[1] = False
# Iterate over the numbers from 2 to sqrt(limit)
for i in range(2, int(limit**0.5) + 1):
if is_prime[i]:
# Mark all multiples of i as composite numbers
for j in range(i**2, limit + 1, i):
is_prime[j] = False
# Generate the list of prime numbers
primes = [i for i in range(2, limit + 1) if is_prime[i]]
return primes
```
The function first initializes a boolean array `is_prime` of size `limit + 1` with all entries set to `True`, except for the first two entries which represent 0 and 1, which are not prime. Then, the function iterates over the numbers from 2 to the square root of `limit`, checking ifeach number is prime and marking its multiples as composite numbers in the `is_prime` array. Finally, the function generates a list of prime numbers based on the `is_prime` array and returns it.
To use the function, simply call it with a limit value and assign the returned list of primes to a variable, like this:
```python
primes = generate_primes(20)
print(primes)
```
This will generate a list of all prime numbers up to 20 and print it:
```
[2, 3, 5, 7, 11, 13, 17, 19]
```