If you know the distribution of random numbers, for instance if you know that the numbers come randomly from an interval (0,L) of real numbers, then your probability of winning is

2/3, or about 66% of the trials, of you use the same random to base the decision, and

3/4, so **75%** of the trials, if you use the median of the distribution

To see the first, pick a third random number from the same distribution. Then the probability of this number to be between the other two is 1/3, as you can check from the six equally possible permutations, and in this case the strategy always selects the right answer. If the number is greater and smaller that both boxes, you have still 1/2 probability of random guess, to total prob is 1/3 + 2/3 * 1/2 = 2/3

To check this, you can try the following Python program:

```
from random import random
trials, winrandom, winmethod=0,0.0,0.0
while trials < 10000:
abox=random()
bbox=random()
print abox,bbox
trials +=1
choose = "a" if random() < 0.5 else "b"
if choose=="a" and abox > bbox: winrandom +=1
if choose=="b" and bbox > abox: winrandom +=1
decide = "a" if random() < abox else "b"
if decide=="a" and abox > bbox: winmethod +=1
if decide=="b" and bbox > abox: winmethod +=1
print trials, winrandom/trials, winmethod / trials
```

Generically, if you use a different distribution of probability, your total prob is still given by the formula offered in the other solutions, $ p+ {1\over 2} (1-p)$, or $${1\over 2} + {1\over 2} p $$

with $p$ the probability of the random number to be between the two boxes. Note that some formulae combine this $p$ with the one of the first box being smaller that the second, to hide the 1/2 factor.

A distribución concentrated on the median of the original one is a better strategy, because the prob of the median to be between both numbers is 0.5, and so the winning prob raises up to the 75%.