Popular recipes tagged "prime_generator" but not "algorithms"http://code.activestate.com/recipes/tags/prime_generator-algorithms/2013-01-19T03:58:05-08:00ActiveState Code Recipes"Effcient" Prime Number Generator in Python (Python) 2013-01-19T03:58:05-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578402-effcient-prime-number-generator-in-python/ <p style="color: grey"> Python recipe 578402 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a></p> <p>Please Note. This is only efficient per the article discussing this code in the link above. See comments for a better library to generate prime numbers.</p> Find the nth prime in python (Python) 2013-01-06T20:23:21-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578403-find-the-nth-prime-in-python/ <p style="color: grey"> Python recipe 578403 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a nth prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a></p> Genreate x digits prime number in python, version 2 (Python) 2013-01-06T20:27:09-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578405-genreate-x-digits-prime-number-in-python-version-2/ <p style="color: grey"> Python recipe 578405 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>). </p> <p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>. The script will generate a prime number of x digits, where x is less than 15. It might work for larger x, but it will take a while. </p> Genreate x digits prime number in python, version 1 (Python) 2013-01-06T20:25:20-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578404-genreate-x-digits-prime-number-in-python-version-1/ <p style="color: grey"> Python recipe 578404 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>. The script will generate a prime number of x digits for small numbers, less than 10. </p> Simple Prime Number Generator in Python (Python) 2013-01-06T20:18:38-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578400-simple-prime-number-generator-in-python/ <p style="color: grey"> Python recipe 578400 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a simple prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>.</p> <p>Note: There are more efficient ways to do this. Please look at my other recipes. </p> Prime Number Generator in Python (half effcient) (Python) 2013-01-06T20:20:49-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578401-prime-number-generator-in-python-half-effcient/ <p style="color: grey"> Python recipe 578401 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a simple prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>. In this one we cut the numbers in half so it is only slightly more efficient than the simplest prime number generator. </p> <p>Note: There are more efficient ways to do this. Please look at my other recipes. </p> Even faster prime generator (C++) 2011-11-27T21:48:25-08:00Sumudu Fernandohttp://code.activestate.com/recipes/users/4180103/http://code.activestate.com/recipes/577966-even-faster-prime-generator/ <p style="color: grey"> C++ recipe 577966 by <a href="/recipes/users/4180103/">Sumudu Fernando</a> (<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>). </p> <p>A very quick (segmented) sieve of Eratosthenes.</p> <p>Takes ~6s on a midrange machine to hit all 50 847 534 primes less than 1 billion, ending with 999999937</p> <p>If you want to actually <em>do</em> anything with every prime (beyond counting them), there are three places to add a statement doing whatever is necessary with "lastP" -- one at the top (handles the special case '2'), one in the middle (handles "small" primes which are actually used to sieve), and one at the bottom (handles "large" primes which merely survive sieving).</p> <p>In principle one can use a function object as parameter to allow generic operations on the primes, so add that if you want more general-purpose code (perhaps I'll do that later)</p> <p>For higher limits you need to switch to wider types and follow the commented guidelines for the constants. For a fixed limit, changing <code>B_SIZE</code> may affect performance so if needed tune it (profile as you go, of course!). But this will get quite slow if you go to much higher numbers.</p> Sieve of Eratosthenes (Prime Generator) (Python) 2011-11-27T08:27:25-08:00Assil Ksiksihttp://code.activestate.com/recipes/users/4180094/http://code.activestate.com/recipes/577965-sieve-of-eratosthenes-prime-generator/ <p style="color: grey"> Python recipe 577965 by <a href="/recipes/users/4180094/">Assil Ksiksi</a> (<a href="/recipes/tags/eratosthenes/">eratosthenes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>). </p> <p>A simple implementation of the Sieve of Eratosthenes in Python. The code should be self-explanatory, but I've added a docstring and some comments just in case.</p> <p>Constructive criticism is of course appreciated.</p> Faster prime generator (C++) 2011-10-08T23:26:24-07:00Mathijs Romanshttp://code.activestate.com/recipes/users/4179530/http://code.activestate.com/recipes/577899-faster-prime-generator/ <p style="color: grey"> C++ recipe 577899 by <a href="/recipes/users/4179530/">Mathijs Romans</a> (<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>). </p> <p>The sieve of Eratosthenes implemented in C++. I noticed <a href="http://code.activestate.com/recipes/576559-fast-prime-generator/">another recipe</a> that could be improved upon, making it faster and a bit prettier.</p> A fast & memory-wise prime number generator up to N (Python) 2010-08-13T18:28:00-07:00robert.william.hankshttp://code.activestate.com/recipes/users/4174481/http://code.activestate.com/recipes/577357-a-fast-memory-wise-prime-number-generator-up-to-n/ <p style="color: grey"> Python recipe 577357 by <a href="/recipes/users/4174481/">robert.william.hanks</a> (<a href="/recipes/tags/fast/">fast</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Using python 2.6 &amp; numpy. This code was first posted <a href="http://stackoverflow.com/questions/2897297/speed-up-bitstring-bit-operations-in-python/2908512#2908512">here</a></p> Fast prime generator (C++) 2008-11-30T00:40:23-08:00Florian Mayerhttp://code.activestate.com/recipes/users/4165843/http://code.activestate.com/recipes/576559-fast-prime-generator/ <p style="color: grey"> C++ recipe 576559 by <a href="/recipes/users/4165843/">Florian Mayer</a> (<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>). Revision 2. </p> <p>This is the sieve of Eratosthenes implemented in C++.</p>