Is there a public prime table in .NET.

I know that there is one that is used in all types of .NET dictionaries and head tables:

internal static class HashHelpers

  • Is it public, somewhere else?
  • If not, why is it stored internally, isn't it used very often?
  • Is copying and pasting a transition method if I need primes in my code?
+6
source share
2 answers
  • As far as I know, in .NET there is no public version of this table.
  • Since this table is not a table of all primes in the range, it is a table of an arbitrarily selected subset of primes suitable for a specific purpose (hash-based dimensional containers)
  • No, you must either generate your own table on the fly, or copy the table from one of many complete sources.
+5
source

I can not answer your question regarding the availability of HashHelpers, but here are the ways to implement it themselves.

Here's a post with some imperative implementations when generating prime numbers: The most elegant way to generate prime numbers

Alternatively, you can do this in LINQ:

 var odds = from n in Enumerable.Range(0, int.MaxValue) select 3 + (long) n * 2; var primes = (new[] { 2L }).Concat( from p in odds where ! odds.TakeWhile(odd => odd * odd <= p).Any(odd => p % odd == 0) select p); 

Source: http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/

Edit: do not use int.MaxValue in your initial range. Limit this to something suitable.

+3
source

Source: https://habr.com/ru/post/921664/


All Articles