- #1

donglepuss

- 13

- 1

If I select two integers at random, what is the probability that their sum will be prime?

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- I
- Thread starter donglepuss
- Start date

- #1

donglepuss

- 13

- 1

If I select two integers at random, what is the probability that their sum will be prime?

- #2

jedishrfu

Mentor

- 14,059

- 8,019

This is a tough question to answer since we have no formula for primes. The simplest approach would be to write a python program to do the work. It would need a list of primes and a range of numbers to start with.

As an example, the range of 1-10 then the highest prime is 19 ie 9+10 and so in general highest prime would be < 2N where N is the top number in the range of numbers 1-N. From there you can create estimates of the number of primes found between 1-10, 1-100, 1-1000 ...

As an example, the range of 1-10 then the highest prime is 19 ie 9+10 and so in general highest prime would be < 2N where N is the top number in the range of numbers 1-N. From there you can create estimates of the number of primes found between 1-10, 1-100, 1-1000 ...

Last edited:

- #3

Vanadium 50

Staff Emeritus

Science Advisor

Education Advisor

2021 Award

- 29,199

- 14,457

What do you mean by this?If I select two integers at random

- #4

hmmm27

Gold Member

- 1,016

- 513

Almost exactly the same as simply selecting one integer [edit: and testing that for primality].If I select two integers at random, what is the probability that their sum will be prime?

- #5

jedishrfu

Mentor

- 14,059

- 8,019

-vs-

1+1 = 2 , and 1+2 = 3, 1+4=5, 1+6=7...

Ahh so 1+ any selected integer to find the prime and then count the number of summing variations to get that prime.

- #6

hmmm27

Gold Member

- 1,016

- 513

- #7

- #8

- 17,594

- 18,140

$$

\lim_{x \to \infty}\dfrac{\pi(x)}{\dfrac{x}{\ln (x)}}=1

$$

Since you haven't restricted any range where we are looking for primes, we need to consider all integers. The relative frequency is thus

$$

\dfrac{\pi(x)}{x} \sim \dfrac{1}{x}\cdot\dfrac{x}{\ln x}=\dfrac{1}{\ln (x)} \stackrel{x\to \infty }{\longrightarrow }0

$$

The probability to pick a prime out of all integers is zero.

- #9

FactChecker

Science Advisor

Gold Member

- 7,442

- 3,220

To get a non-zero answer, we would have to limit the allowable selection to a finite subset.

- #10

- 17,594

- 18,140

- #11

Jarvis323

- 987

- 860

I would think that the probability that the sum of a pair of randomly selected integers between ##n## and ##m## is prime would be a little smaller than the probability that an integer selected randomly between ##n## and ##m## will be prime. Because the expected value of the sum is larger, and the ratio of primes to integers decreases as the numbers get larger.

Here is a program you can use to try and test it:

Going up to 1 million the probabilities look like this:

Here is a program you can use to try and test it:

Python:

```
import sympy
import random
n = 1
m = 100000000
N_ITER = 10000000
n_sum_primes = 0
n_single_primes = 0
for i in range( N_ITER ):
p1 = random.randint( n, m )
p2 = random.randint( n, m )
if( sympy.isprime( p1 ) ) :
n_single_primes += 1
if( sympy.isprime( p1 + p2 ) ) :
n_sum_primes += 1
print( n_sum_primes / N_ITER )
print( n_single_primes / N_ITER )
```

Going up to 1 million the probabilities look like this:

Last edited:

- #12

- 23,240

- 14,750

This is not right, because you've wrongly assumed that the limiting case is a valid probability distribution. Which it is not.The probability to pick a prime out of all integers is zero.

If we select an integer ##n## uniformly from the range ##1-N##, then the probability that ##n## is selected ##p(n) = \frac 1 N##. And, clearly, ##p(n) \rightarrow 0## as ##N \rightarrow \infty##.

However, critically, the limiting case is not a valid probability distribution. We can see this as, in the limiting case of selection from all positive integers we have:

$$\sum_{n = 1}^{\infty}p(n) = \sum_{n = 1}^{\infty} 0 = 0$$

And you can see that the probability space is invalid in the case of the limit. In other words, a uniform probability distribution on ##\mathbb N## does not exist.

Note that we can have a uniform probability distribution on the continuous interval ##[0, 1]##, although not on all of ##\mathbb R##.

The correct answer is that there is no uniform distribution on the integers. The probability of selecting a prime tends to zero as the size of the range increases without bound. But, the limiting case of ##p(n) = 0## for all ##n## is not itself a valid solution.

- #13

jbriggs444

Science Advisor

Homework Helper

- 11,429

- 6,048

Indeed. Which means that we cannot properly pose the question about primes in the naturals as a question about probability.The correct answer is that there is no uniform distribution on the integers.

What we can do is to pose it as a question about asymptotic density.

The asymptotic density of a subset S of the naturals is the limit (if it exists) as ##n## increases without bound of the number of elements of S in the range from 1 through ##n## as a fraction of ##n##.

As @fresh_42 has pointed out, the asymptotic density of the primes in the naturals is zero.

- #14

Vanadium 50

Staff Emeritus

Science Advisor

Education Advisor

2021 Award

- 29,199

- 14,457

He said randomly selected integers, not positive integers.I would think that the probability that the sum of a pair of randomly selected integers between and is prime would be a little smaller than the probability that an integer selected randomly between and will be prime

We are all discussing this assuming he meant something other than what he wrote. Different things.

- #15

Keith_McClary

Gold Member

- 722

- 1,437

To get a non-zero answer, we would have to limit the allowable selection to a finite subset.

What is the simplest proof that the density of primes goes to zero?

- #16

FactChecker

Science Advisor

Gold Member

- 7,442

- 3,220

- #17

- 17,594

- 18,140

Mine, too. Yes, there is no probability distribution and maybe we should have said likelihood instead of probability, or - as I did - relative frequency, or density of primes. And yes, the probability of picking one prime as opposed to a prime as a sum of finitely many integers from a finite set of integers may be slightly different, or not. Fact is, it doesn't matter.

The probability to pick a prime from a finite set of integers ##\{1,\ldots,n\}## is ##1/\ln n##. And, yes, I know that there are better boundaries, so this is again false. Sorry, I should have said: The probability to pick a prime from a finite set of integers ##\{1,\ldots,n\}## is

And here is a special for all nitpickers: How many even prime integers are there?

$$\{-2,+2\}$$

- #18

Baluncore

Science Advisor

2021 Award

- 11,758

- 5,946

You only need generate one random number.If I select two integers at random, what is the probability that their sum will be prime?

The Riemann zeta function approximates the number of primes less than a given magnitude.

Select one random integer, evaluate the derivative of the RZF for that value, and you have the probability that a value of that magnitude will be prime.

Srinivasa Ramanujan also had a good approximation for the RZF.

- #19

- 23,240

- 14,750

I think you mean the prime counting function? The RZF is something else.You only need generate one random number.

The Riemann zeta function approximates the number of primes less than a given magnitude.

Select one random integer, evaluate the derivative of the RZF for that value, and you have the probability that a value of that magnitude will be prime.

That said, if you select an integer and the last digit is not ##1,3,7## or ##9##, then the probability it is prime is zero. With one notable exception.

- #20

Baluncore

Science Advisor

2021 Award

- 11,758

- 5,946

All primes are odd, with the exception of 2, which must make 2 the oddest prime of all.That said, if you select an integer and the last digit is not 1, 3, 7 or 9, then the probability it is prime is zero. With one notable exception.

- #21

Vanadium 50

Staff Emeritus

Science Advisor

Education Advisor

2021 Award

- 29,199

- 14,457

And one less-notable exception.With one notable exception.

- #22

Baluncore

Science Advisor

2021 Award

- 11,758

- 5,946

I guess all four must be the unique factors.

- #23

- 17,594

- 18,140

(2,3,5),(-2,-3,5),(2,-3,-5) and (-2,3,-5) can also be considered as prime factors. Up to units means that units can be arbitrarily distributed.

I guess all four must be the unique factors.

Share:

- Replies
- 26

- Views
- 554

- Last Post

- Replies
- 12

- Views
- 193

- Replies
- 4

- Views
- 390

- Last Post

- Replies
- 24

- Views
- 849

- Last Post

- Replies
- 1

- Views
- 6K

- Replies
- 2

- Views
- 359

- Last Post

- Replies
- 12

- Views
- 554

- Replies
- 2

- Views
- 307

- Last Post

- Replies
- 3

- Views
- 932

- Last Post

- Replies
- 12

- Views
- 733