Reputation: 7931
I know there is one which is used in all kind of .NET dictionaries and hashtables in:
internal static class HashHelpers
Upvotes: 7
Views: 475
Reputation: 726489
Upvotes: 5
Reputation: 40002
I cannot answer your question regarding the availability of HashHelpers, but here are ways of implementing it yourself.
Here a post with some imperative implementations on generating prime numbers: Most elegant way to generate prime numbers
Additionally, you can do it 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: Don't use int.MaxValue in your initial range. Limit this to something appropriate.
Upvotes: 3