ArticleslgStudy

computer science

Generation of primes

Generation of primes is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Generation of primes rather than just read about it. In short: In computational number theory, a variety of algorithms make it possible to generate prime numbers efficiently. These are used in various applications, for example hashing, public-key cryptography, and search of prime factors in large numbers.

Key takeaways

  • Generation of primes belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Generation of primes to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Generation of primes from memory before moving on to harder problems.

Reference excerpt

In computational number theory, a variety of algorithms make it possible to generate prime numbers efficiently. These are used in various applications, for example hashing, public-key cryptography, and search of prime factors in large numbers. For relatively small numbers, it is possible to just apply trial division to each successive odd number. Prime sieves are almost always faster. Prime sieving is the fastest known way to deterministically enumerate the primes. There are some known formulas that can calculate the next prime but there is no known way to express the next prime in terms of the previous primes. Also, there is no effective known general manipulation and/or extension of some mathematical expression (even such including later primes) that deterministically calculates the next prime.

Prime sieves A prime sieve or prime number sieve is a fast type of algorithm for finding primes. There are many prime sieves. The simple sieve of Eratosthenes (250s BCE), the sieve of Sundaram (1934), the still faster but more complicated sieve of Atkin (2003), sieve of Pritchard (1979), and various wheel sieves are most common. A prime sieve works by creating a list of all integers up to a desired limit and progressively removing composite numbers (which it directly generates) until only primes are left. This is the most efficient way to obtain a large range of primes; however, to find individual primes, direct primality tests are more efficient. Furthermore, based on the sieve formalisms, some integer sequences (sequence A240673 in the OEIS) are constructed which also could be used for generating primes in certain intervals. Historically some prime sieves were realised or partly realised in hardware, including the stencils used by Anton Felkel, Carl Hindenburg and D. N. Lehmer as aids to manual computation; and the electromechanical machines, and one later electronic machine, known as the Lehmer sieves by D. H. Lehmer (on at least one occasion with D. N. Lehmer).

Large primes Cryptography requires the use of very large primes: for example, with the RSA cryptosystem two primes of at least 1,024 bits (i.e. at least 21023) are recommended. To generate these primes, the mainstream method is to generate random numbers in a target range and test them for primality using fast probabilistic methods: a short round of sieving (sieve of Eratosthenes or trial division) followed by Baillie–PSW primality test or the Miller–Rabin primality test; a probable prime with a chance of 2-112 of being composite is considered plenty for the 2,048-bit case. Even if a composite number is chosen, it will likely be quickly discovered by causing failed operations, except when a Carmichael number happens to be chosen in the case of RSA. A less common choice is to use provable primes, which can be generated based on variants of Pocklington primality test, especially Maurer's algorithm. Both the provable and probable primality tests rely on modular exponentiation. In addition with RSA, so-called "strong primes" with both p-1 and p+1 having a large prime factor is preferred, as this is expected to slow down factoring attempts using the Polard's p-1 and Williams' p+1 algorithms. Such a choice has little effect against elliptic-curve factoring methods, however. Integers of special forms, such as Mersenne primes or Fermat primes, can be efficiently tested for primality if the prime factorization of p − 1 or p + 1 is known.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Generation of primes

Start with the simplest possible case. Write down what Generation of primes claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Generation of primes before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Generation of primes ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Generation of primes

In research
Generation of primes appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Generation of primes in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Generation of primes is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cryptographic algorithms, Number theoretic algorithms, Prime numbers, so understanding it makes those chapters shorter.
In everyday life
Look for Generation of primes outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Generation of primes in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Generation of primes means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Generation of primes out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Generation of primes in simple terms?

In computational number theory, a variety of algorithms make it possible to generate prime numbers efficiently. These are used in various applications, for example hashing, public-key cryptography, and search of prime factors in large numbers.

Why does Generation of primes matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Generation of primes?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Generation of primes.

Tags

  • Cryptographic algorithms
  • Number theoretic algorithms
  • Prime numbers

Keep exploring