Given Prime Number N, Compute the Next Prime?

后端 未结 9 1766
忘掉有多难
忘掉有多难 2020-11-29 17:41

A coworker just told me that the C# Dictionary collection resizes by prime numbers for arcane reasons relating to hashing. And my immediate question was, \"how does it know

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 18:18

    Just a few experiments with inter-primes distance.


    This is a complement to visualize other answers.

    I got the primes from the 100.000th (=1,299,709) to the 200.000th (=2,750,159)

    Some data:

    Maximum interprime distance = 148
    
    Mean interprime distance = 15  
    

    Interprime distance frequency plot:

    alt text

    Interprime Distance vs Prime Number

    alt text

    Just to see it's "random". However ...

提交回复
热议问题