Monday, November 10, 2025

Even more so, seems like an actual uniform generator would be simpler…

Randy has an updated suggestion for how the button should behave at door 2. What hasn’t changed is that if a contestant at door 2 and moves to an adjacent door, that new door will be 1 or 3 with equal probability.

But this time, on the first, third, fifth, and other odd button presses that happen to be at door 2, there’s a 20 percent the contestant remains at door 2. On the second, fourth, sixth, and other even button presses that happen to be at door 2, there’s a 50 percent chance the contest remains at door 2.

Meanwhile, the button’s behavior at doors 1 and 3 should in no way depend on the number of times the button has been pressed.

As the producer, you want the chances of winding up at each of the three doors—after a large even number of button presses— to be nearly equal. If a contestant presses the button while at door 1 (or door 3), what should the probability be that they remain at that door?

In this case, let $q$ be the probability of remaining at door 1 (or at door 3), then we can treat the two different behaviors at door 2 sequentially in order to come with the two-step transition matrix \begin{align*}Q & = \begin{pmatrix} q & 1-q & 0 \\ 0.4 & 0.2 & 0.4 \\ 0 & 1-q & q \end{pmatrix} \begin{pmatrix} q & 1-q & 0 \\ 0.25 & 0.5 & 0.25 \\ 0 & 1-q & q \end{pmatrix} \\ & = \begin{pmatrix} q^2 -\frac{1}{4}q +\frac{1}{4} & -q^2 + \frac{1}{2} q +\frac{1}{2} & -\frac{1}{4}q + \frac{1}{4}\\ \frac{2}{5}q + \frac{1}{20} & -\frac{4}{5}q + \frac{9}{10} & \frac{2}{5}q + \frac{1}{20}\\ -\frac{1}{4}q + \frac{1}{4} & -q^2 + \frac{1}{2} q + \frac{1}{2} & q^2 -\frac{1}{4}q + \frac{1}{4}\end{pmatrix}.\end{align*}

We will lean upon our own great (?) shoulders from the Classic problem to show that we need to solve for $q$ that makes the transition matrix symmetric. In this case, that requirement yields $$\frac{2}{5}q + \frac{1}{20} = -q^2 + \frac{1}{2} q + \frac{1}{2},$$ or equivalently, $$q^2 -\frac{1}{10} q - \frac{9}{20} = 0.$$ Solving this quadratic for the positive root (since after all we need $q\in[0,1]$ as a probability), gives that the appropriate probability to remain at door 1 in this even more complicated Markov scheme is $$q=\frac{ \frac{1}{10} + \sqrt{ \frac{1}{100} + 4 \frac{9}{20} } }{2} = \frac{1+\sqrt{181}}{20} \approx 0.722681202354\dots$$

Seems like an actual uniform generator would be simpler…

You are a producer on a game show hosted by Randy “Random” Hall (no relation to Monty Hall). The show has three doors labeled 1 through 3 from left to right, and behind them are various prizes.

Contestants pick one of the three doors at which to start, and then they press an electronic button many, many times in rapid succession. Each time they press the button, they either stay at their current door or move to an adjacent door. If they’re at door 2 and move to an adjacent door, that new door will be 1 or 3 with equal probability.

Randy has decided that when a contestant presses the button while at door 2, there should be a 20 percent chance they remain at door 2.

As the producer, you want the chances of a contestant ultimately winding up at each of the three doors to be nearly equal after many button presses. Otherwise, mathematicians will no doubt write you nasty letters complaining about how your show is rigged.

If a contestant presses the button while at door 1 (or door 3), what should the probability be that they remain at that door?

Firstly, so true ... if there were a meaningful bias in the supposedly uniformly random process of selecting which door, I would take notice. Though rather than calling to complain I would be more likely to try to get on the show to exploit this bias, but I guess potato-potato.

Moving on, per Randy's specifications and your desire for the appearance of uniform randomness, we have a three state Markov chain setup where the transition matrix $$P= \begin{pmatrix} p & 1-p & 0 \\ 0.4 & 0.2 & 0.4 \\ 0 & 1-p & p \end{pmatrix}$$ and we are wondering for which values of $p$ will $P^n \to U,$ as $n\to \infty$, where the limiting matrix $U$ is the $3\times 3$ matrix where each entry is $\frac{1}{3}.$

There are many ways to solve for $p$ here. For instance, though we would obviously start with some specific position, e.g., $\pi_0 = (1,0,0)$, if $P^n \to U,$ as $n\to \infty$, then we would necessarily need to have $u=(\frac{1}{3},\frac{1}{3},\frac{1}{3})$ satisfy $uP=u$. We could obviously just solve here and get three linear equations (that hopefully collapse well since there is only one unknown), but instead let's math out!

Since $P$ is a transition matrix its rows sum to one, so we see that $Pu^T=u^T,$ which if we combine with $uP=u$ implies the $$Pu^T= u^T = (uP)^T = P^Tu^T.$$ So $P$ must be symmetric $(P=P^T)$, which leaves the much easier linear equation $1-p=0.4,$ that is, in order to provide the illusion of a uniform distibution of the door's landing spot through this elaborate Markov scheme you must have the probability of remaining on door 1 when the button is pressed be $p=60\%.$

Of course, armed with the knowledge that we have a symmetric transition matrix, we can then justify that this works by using the Spectral Theorem. We have already seen that $\lambda=1$ and $u^T$ is an eigenpair. We could certainly additionally calculate the other two eigenpairs as well, or simply argue that the eigenvalues must have absolute value less than $1$ and that the eigenvectors can be chosen to be an orthonormal basis of $\mathbb{R}^3$, such that $P=VDV^T,$ where $D = diag(1, \lambda_2, \lambda_3)$ and $$V= \begin{pmatrix} \sqrt{3}/3 & v_{12} & v_{13} \\ \sqrt{3}/3 & v_{22} & v_{23} \\ \sqrt{3}/3 & v_{32} & v_{33} \end{pmatrix}$$ satisfies $V^TV=VV^T=I.$ Since this $V$ represents an orthonormal basis we can change bases and represent any initial $\pi_0$ in $V$-coordinates, where the first coordinate is also $\sqrt{3}/3$ whenever $\pi_0$ sums to $1.$ Let's generically assume that $\pi_0 v_2 = c_2 \in \mathbb{R}$ and $\pi_0 v_3 = c_3 \in \mathbb{R}.$ Then we see that \begin{align*}\pi_n = \pi_{n-1} P &= \pi_{n-1} VDV^T \\ &= \cdots = \pi_0 V D^n V^T \\ &= u + c_2 \lambda_2^n v_2^T + c_3 \lambda_3^n v_3^T\end{align*} Since $|\lambda_2|, |\lambda_2| \lt 1,$ we see that for any value of $\pi_0$ we get $\pi_n \to u,$ as desired.

Sunday, November 2, 2025

Extra Credit swinging the probabilities, or ... Hey, how'd the Catalan numbers show up here???

Instead of a best-of-seven series, now suppose the series is much, much longer. In particular, the first team to win $N$ games wins the series, so technically this is a best-of-($2N−1$) series, where $N$ is some very, very large number.

In the limit of large $N$, what is the probability swing for Game 1 in terms of $N$?

Applying the same logic used in the Classic Fiddler problem, we want to first find $p_{1,N} = \mathbb{P} \{ \text{win best of (2N-1) series} \mid \text{win game 1} \},$ from which we get the probability swing of game 1 in a best of $(2N-1)$ series as $\Delta_N = 2p_{1,N} - 1.$ Again following in the Classic Fiddler's solution's footsteps, if you win games $1$ and $k$, then there are $\binom{k-2}{N-2}$ ways of arranging another $N-2$ wins in the other $k-2$ games, so $$p_{1,k,N} = \mathbb{P} \{ \text{winning a best of $(2N-1)$ series in $k$ games} \mid \text{win game 1} \} = \binom{k-2}{N-2} \frac{1}{2^{k-1}}.$$ Summing over all possible values of $k = N, N+1, \dots, 2N-1,$ we get $$p_{1,N} = \sum_{k=N}^{2N-1} \binom{k-2}{N-2} \frac{1}{2^{k-1}}.$$ We could try to go further and define some generating function f_N, but this would lead to some escalating number of derivatives, that gets messy fast.

Instead let's set up a recursive formula. We note that $p_{1,1} = 1,$ which makes sense since it is a winner-takes-all one game playoff. For some $N \geq 1,$ let's take a look at $$p_{N+1} = \sum_{k=N+1}^{2N+1} \binom{k-2}{N-1} \frac{1}{2^{k-1}}.$$ The standard binomial coefficient recursion formula (which comes from the Pascal triangle) gives $$\binom{k-2}{N-1} = \binom{k-3}{N-1} + \binom{k-3}{N-2},$$ so we have \begin{align*} p_{N+1} & = \sum_{k=N+1}^{2N+1} \left(\binom{k-3}{N-1} + \binom{k-3}{N-2} \right) \frac{1}{2^{k-1}} \\ &= \left( \sum_{k=N}^{2N} \binom{k-2}{N-1} \frac{1}{2^k} \right) + \left( \sum_{k=N}^{2N} \binom{k-2}{N-2} \frac{1}{2^k} \right) \\ &= \frac{1}{2} \left( \sum_{k=N+1}^{2N} \binom{k-2}{N-1} \frac{1}{2^{k-1}} \right) + \frac{1}{2} \left( \sum_{k=N}^{2N-1} \binom{k-2}{N-2} \frac{1}{2^{k-1}} \right) + \binom{2N-2}{N-2} \frac{1}{2^{2N}} \\ &= \frac{1}{2} p_{1,N+1} - \binom{2N-1}{N-1} \frac{1}{2^{2N+1}} + \frac{1}{2} p_{1,N} + \binom{2N-2}{N-2} \frac{1}{2^{2N}}.\end{align*} Pulling the copy of $\frac{1}{2}p_{1,N+1}$ back onto the lefthand side and then multiplying by 2, we get the recursion formula \begin{align*} p_{1,N+1} &= p_{1,N} + \binom{2N-2}{N-2} \frac{1}{2^{2N-1}} - \binom{2N-1}{N-1} \frac{1}{2^{2N}} \\ &= p_{1,N} + \binom{2N-2}{N-2} \frac{1}{2^{2N-1}} - \left( \binom{2N-2}{N-1} + \binom{2N-2}{N-2} \right) \frac{1}{2^{2N}} \\ &= p_{1,N} - \frac{1}{4^N} \left( \binom{2N-2}{N-1} - \binom{2N-2}{N-2} \right) \\ &= p_{1,N} - \frac{1}{4^N} C_{N-1}, \end{align*} where $C_n = \frac{1}{n+1} \binom{2n}{n} = \binom{2n}{n} - \binom{2n}{n+1},$ for $n \in \mathbb{N}$ is the standard Catalan number.

Since we start with $p_{1,1} = 1,$ we then see that $$p_{1,N} = 1 - \sum_{k=1}^{N-1} \frac{C_{k-1}}{4^k} = 1 - \frac{1}{4} \sum_{k=0}^{N-2} \frac{C_k}{4^k}, \,\, \forall N \in \mathbb{N}.$$ We can rely on the fact that the generation function of the Catalan numbers is $$c(x) = \sum_{n=0}^\infty C_n x^n = \frac{1 - \sqrt{1-4x}}{2x},$$ so that $$\frac{1}{4} \sum_{k=0}^\infty \frac{C_k}{4^k} = \frac{1}{4} c(\frac{1}{4}) = \frac{1}{4} \frac{1 - \sqrt{1 - 4 \cdot \frac{1}{4}}}{2 \cdot \frac{1}{4}} = \frac{1}{2}.$$ Therefore, we see that $$p_{1,N} = 1 - \frac{1}{4} \sum_{k=0}^{N-2} \frac{C_k}{4^k} = 1 - \frac{1}{4} \sum_{k=0}^\infty \frac{C_k}{4^k} + \frac{1}{4}\sum_{k=N-1}^\infty \frac{C_k}{4^k} = \frac{1}{2} + \frac{1}{4} \sum_{k=N-1}^\infty \frac{C_k}{4^k},$$ for all $N \in \mathbb{N}.$ Now when $k$ is large we have $$C_k \sim \frac{4^k}{k^{3/2} \sqrt{\pi}},$$ from repeated applications of Stirling's approximation, so when $N$ is sufficiently large we have $$\frac{1}{4} \sum_{k=N-1}^\infty \frac{C_k}{4^k} \approx \frac{1}{4\sqrt{\pi}} \sum_{k=N-1}^\infty k^{-3/2} \approx \frac{1}{2\sqrt{\pi (N-1)}},$$ where the last approximation is due to the fact that $\sum_{k=N}^\infty k^{-p} \sim \int_N^\infty x^{-p} \,dx.$ Therefore, in a fairly concise way, we have $$p_{1,N} \approx \frac{1}{2} + \frac{1}{2\sqrt{\pi(N-1)}},$$ when $N$ is large, so the probability swing of winning the first game is $$\Delta_N = 2p_{1,N} -1 \approx \frac{1}{\sqrt{\pi(N-1)}}$$ when $N$ is large.

Swinging the probabilities

You and your opponent are beginning a best-of-seven series, meaning the first team to win four games wins the series. Both teams are evenly matched, meaning each team has a 50 percent chance of winning each game, independent of the outcomes of previous games.

As the team manager, you are trying to motivate your team as to the criticality of the first game in the series (i.e., “Game 1”). You’d specifically like to educate them regarding the “probability swing” coming out of Game 1—that is, the probability of winning the series if they win Game 1 minus the probability of winning the series if they lose Game 1. (For example, the probability swing for a winner-take-all Game 7 is 100 percent.)

What is the probability swing for Game 1?

Let's break this down as follows. Let $p_1 = \mathbb{P} \{ \text{win series} \mid \text{win game 1} \}.$ In order to win the series, you must win it in $k$ games for some $k=4, 5, 6, 7,$ so let's further let $$p_{1,k} = \mathbb{P} \{ \text{win series in $k$ games} \mid \text{win game 1} \},$$ where here we see that $p_1 = \sum_{k=4}^7 p_{1,k}.$ Now, the total number of ways to win the first and $k$th games and two others somewhere in games $2$ through $k-1$ is given by $\binom{k-2}{2}$ and the overall probability of any particular combination of $k$ games is $\frac{1}{2^k},$ so $$p_{1,k} = \frac{\mathbb{P} \{ \text{win series in $k$ games and win game $1$} \}}{\mathbb{P} \{ \text{win game 1 } \}} = \binom{k-2}{2} \frac{1}{2^{k-1}}.$$ Therfore, $$p_1 = \sum_{k=4}^7 \binom{k-2}{2} \frac{1}{2^{k-1}} = \frac{1}{2} \sum_{k=4}^7 \binom{k-2}{2} \frac{1}{2^{k-2}} = \frac{1}{2} \sum_{k=2}^5 \binom{k}{2} \frac{1}{2^k}.$$

Now one way of computing $p_1$ would be using some generating function wizardry. Define the function $f(x) = \sum_{k=2}^5 \binom{k}{2} x^k,$ in which case, $p_1 = \frac{1}{2} f(\frac{1}{2}).$ Now we also see that \begin{align*} f(x) &= \frac{1}{2} x^2 \sum_{k=2}^5 k(k-1) x^{k-2} \\ &= \frac{1}{2} x^2 \frac{d^2}{dx^2} \left( \frac{1-x^6}{1-x} \right) \\ &= \frac{1}{2} x^2 \frac{d}{dx} \left( \frac{1-6x^5+5x^6}{(1-x)^2} \right) \\ &= \frac{1}{2} x^2 \frac{2(1-15x^4+24x^5-10x^6}{(1-x)^3} \\ &= \frac{ x^2 ( 1 - 15 x^4 + 24x^5 -10x^6) }{(1-x)^3}.\end{align*} So we have $$p_1 = \frac{1}{2} f(\frac{1}{2}) = \frac{1}{2} \frac{ \frac{1}{4} \left( 1 - \frac{15}{16} + \frac{24}{32} - \frac{10}{64} \right) }{ \frac{1}{8} } = \frac{ 42}{64} = \frac{21}{32}.$$

Now from symmetry, we see that the probability of you winning having lost the first game, let's say $q_1 = \mathbb{P} \{ \text{win series} \mid \text{lose game 1} \}$ is the same as the probability of you winning the series having lost the series having won the first game. That is $q_1 = 1 - p_1.$ So the proabbility swing of the first game is $$\Delta = p_1 - q_1 = p_1 - (1- p_1) = 2p_1 - 1 = 2 \frac{21}{32} - 1 = \frac{5}{16} = 32.125\%.$$

Sunday, October 26, 2025

Mob rules: implied odds for binary outcomes based on bet frequency

Suppose there are two leading candidates, A and B, for MVP in the Fiddler Baseball League.

Part 1:

Assume the odds for A winning the award have been set to $+100x$, where $x \gt 1$. Let $f$ represent the fraction of dollars wagered in favor of A. For many values of $f$, the oddsmaker can set the odds for B so that they’ll make the same amount of money regardless of whether A or B wins the award. However, below a certain value of $f$, it’s impossible for the oddsmaker to do this. What is this critical value of f?

In this case, if A wins then the oddsmaker must pay out $-xf$ to the bettors who supported A but receive $+(1-f)$ from the losing bettors who supported B, so the total cashflow if A wins is $$\pi_A(x,f) = 1-(x+1)f.$$ Let's assume that if B wins that the oddsmaker will have to pay out $-\rho(1-f),$ for some $\rho \gt 0,$ while they would receive $+f$ from all of the losing A bettors. In this case, the total cashflow if B wins is $$\pi_B(f,\rho) = f - \rho(1-f).$$ If the oddsmaker wants to make sure that $$\pi = \pi_A = 1 - (x+1)f = f - \rho(1-f) = \pi_B,$$ then we would need to set the payoff ratio for B to be $$\rho = \rho(x,f) = - \frac{1 - (2+x)f}{1-f}.$$ Since we need to have $\rho \gt 0,$ and $1-f \gt 0$ by definition since $f \in (0,1),$ we must have $1 - (2+x) f \lt 0$ or equivalently $$f \gt \frac{1}{2+x}.$$ Ideally, the bookmaker wants to make a profit so we would also want to make sure that $\pi = 1 - (x+1)f \gt 0,$ so $$f \lt \frac{1}{1+x}.$$ Now we can convert the payoff ratio as follows: if $\rho \geq 1,$ then the odds for B should be $+100\rho;$ whereas, if $\rho \in (0,1)$ then the odds for B should be $-100 / \rho.$ Therefore, if the odds for A are $+100x,$ then as long as $$f \in \left(\frac{1}{2+x}, \frac{1}{1+x}\right)$$ the oddsmaker can make a profit of $\pi = 1-(1+x)f \gt 0,$ regardless of outcome.

Part 2:

Now, assume the odds for A winning the award have been set to $-100y$, where $y \gt 1$. Again, for many values of $f$, the oddsmaker can set the odds for B so they’ll make the same amount whether A or B wins the award. What is the critical value of $f$ below which this isn’t possible?

In this case, if A wins the oddsmaker must pay out $-\frac{f}{y}$ to the bettors who supported A but receive +(1-f) from the losing bettors who support B, so the total cashflow if A wins is $$\pi_A(y,f) = 1 - \left(1 + \frac{1}{y}\right) f.$$ Let's assume that if B wins that the oddsmaker will have to payout $-\varrho (1-f),$ for some $\varrho \gt 0,$ while they would receive $+f$ from all of the losing A bettors. In this case, the total cashflow if B wins is $$\pi_B(f,\varrho) = f - \varrho(1-f).$$ If the oddsmaker wants to make sure that $$\pi = \pi_A = 1 - \left(1+\frac{1}{y}\right)f = f - \varrho(1-f) = \pi_B,$$ then we would need to set the payoff ratio for B to be $$\varrho = \varrho(y,f) = - \frac{y - (2y+1)f}{y(1-f)}.$$ Since we need to have $\varrho \gt 0,$ and $1-f \gt 0$ by definition since $f \in (0,1),$ we must have $y - (2y+1) f \lt 0$ or equivalently $$f \gt \frac{y}{2y+1}.$$ Ideally, the bookmaker wants to make a profit so we would also want to make sure that $\pi = 1 - \left(1+\frac{1}{y}\right)f \gt 0,$ so $$f \lt \frac{y}{1+y}.$$ Now we can convert the payoff ratio as follows: if $\varrho \geq 1,$ then the odds for B should be $+100\varrho;$ whereas, if $\varrho \in (0,1)$ then the odds for B should be $-100 / \varrho.$ Therefore, if the odds for A are $-100y,$ then as long as $$f \in \left(\frac{y}{2y+1}, \frac{y}{1+y}\right)$$ the oddsmaker can make a profit of $\pi = 1-\left(1+\frac{1}{y}\right)f \gt 0,$ regardless of outcome.

MAWGWTWFMVP

With the regular season over, there are two clear favorites for baseball’s American League Most Valuable Player (MVP) award according to ESPN:

  • Aaron Judge of the New York Yankees, whose odds are $-150$.
  • Cal Raleigh of the Seattle Mariners, whose odds are $+110$.

While these betting lines may be informed by an assessment of Judge’s and Raleigh’s real chances, they may also be informed by how much money people are betting on each player. Suppose all bettors have wagered on either Judge or Raleigh with the odds above. Some fraction $f$ of dollars wagered have been in favor of Judge, while $1−f$ has been wagered on Raleigh. For what fraction $f$ will the oddsmaker earn the same amount of money, regardless of which player earns the MVP award?

Let's normalize everything so that there is a total of one unit of total dollars wagered. When the Baseball Writers Association of America rightfully crowns Cal Raleigh as the AL MVP, the bookmaker will happily take the $+f$ from all the sad crybaby losers who were enthralled by everything New York Yankees. On the other hand in this case, the bookmaker would have to payout a total of $-1.1(1-f) = 1.1f - 1.1$ to the rational baseball afficianados who saw through the glitz, glamour and sour grapes of the East Coast media blitz for Judge and bet on Raleigh. So the total cashflow for the oddsmaker is $+f + 1.1f - 1.1 = 2.1f-1.1.$

On the other hand, just from a pure devil's advocacy perspective, there could be some happenstance where Raleigh could theoretically lose the AL MVP (tvu!, tvu!, tvu!, bli ayin hara!), ranging from the incompetent (the BBWAA forgot to change over its ballots from last year), to the patehtic (the geriatric writers couldn't stay up past their East Coast bedtimes to watch the pure and utter dominace of Raleigh), to any number of more nefarious, perverse chicanery. In this purely theoretical scenario, the oddsmaker would have a total payout of $-\frac{f}{1.5} = -\frac{2f}{3}$ to those delusional Judge patrons, while they would take the $+(1-f)$ from the hard-working, salt-of-the-earth, righteous Raleigh boosters. In this infinitesimally remote scenario, the total cashflow for the oddsmaker is $-\frac{2f}{3} + 1 -f = 1 - \frac{5f}{3}.$

A sober, dispassionate bookmaker would want these two cashflows to align, no matter how justified he might be in skewing it towards Raleigh's side. In this case, the only justification for having the oddsmaker set Raleigh as the underdog in this AL MVP race is because the two sides would net the same amount of positive cashflow if $$2.1f - 1.1 = 1 - \frac{5f}{3},$$ that is, $$f = \frac{2.1}{2.1 + \frac{5}{3}} = \frac{63}{113} \approx 0.55752212389\dots$$ of all bets were for Judge, for some ungodly reason.

Sunday, October 19, 2025

Average Distance from Center of a Unit Cube to Its Surface

Let’s raise the stakes by a dimension. Now, you start at the center of a unit cube. Again, you pick a random direction to move in, with all directions being equally likely. You move along this direction until you reach a point on the surface of the unit cube. On average, how far can you expect to have traveled?

So unlike shifting the shape that we are trying to hit the perimeter of, in the Extra Credit problem, we instead increase the dimensionality. Here $$B_\infty = \left\{ (x,y,z) \in \mathbb{R}^3 \mid \max \{ |x|, |y|, |z| \} = \frac{1}{2} \right\}.$$ Also, instead of parameterizing the direction of travel by a single bearing with respect to the positive $x$-axis, here we need to have two angles, one $\theta \in [0, \pi]$ with respect to the positive $z$-axis and a second $\varphi \in [0,2\pi)$ with respect to the positive $x$-axis. Since the differential of the solid angle of a region of the surface of the sphere is $d\Omega = \sin \theta \,d\varphi \,d\theta$ and the entire surface area of a unit sphere is $4\pi,$ we see that the join distribution function for $\theta$ and $\varphi$ is $$f(\theta, \varphi) = \frac{\sin \theta}{4\pi}.$$ Now, again assuming a unit speed, and given we get the position vector $$r(t) = ( t \cos \varphi \sin \theta, t \sin \varphi \sin \theta, t \cos \theta ).$$

Since you will hit $B_\infty$ whenever $t \max \{ |\cos \varphi \sin \theta|, |\sin \varphi \sin \theta|, |\cos \theta| \} = \frac{1}{2},$ so therefore the distance traveled is \begin{align*} d(\theta, \varphi) &= \frac{1}{2 \max \{ |\cos \varphi \sin \theta|, |\sin \varphi \sin \theta|, |\cos \theta| \}} \\ & = \frac{1}{2} \min \{ |\sec \varphi| \csc \theta, |\csc \varphi| \csc \theta, |\sec \theta | \}, \end{align*} where the final equation removes $\csc \theta$ from the absolute values since $\sin \theta, \csc \theta \geq 0$ for all $\theta \in [0,\pi]$

Therefore, the average distance is $$\hat{d} = \frac{1}{4\pi} \int_0^\pi \int_0^{2\pi} d(\theta, \varphi) \sin \theta \,d\varphi \, d\theta.$$ Now we can decompose this integral into three regions, two of which seem to have analytical solutions, so let's try even though we could just stop here and do the larger integral right here and right now.

Let's only worry about the upper hemisphere, that is $0 \leq \theta \leq \frac{\pi}{2}$. Here we can then break the range into the following three sections:

  • Region I - when $0 \leq \theta \leq \frac{\pi}{4},$ where you will eventually hit the top of the unit cube no matter what the value of $\varphi$;
  • Region II - when $\cos^{-1} \frac{1}{\sqrt{3}} \leq \theta \leq \frac{\pi}{2},$ where you will eventually hit one of the vertical sides of the unit cube no matter what the value of $\varphi$; and
  • Region III - when $\frac{\pi}{4} \leq \theta \leq \cos^{-1} \frac{1}{\sqrt{3}},$ where depending on the value of $\varphi$ you will either hit the top or the sides.

In other words, in Region I, $$d_1(\theta, \varphi) = \frac{1}{2} |\sec \theta|, \forall \varphi \in [0,2\pi),$$ so we have \begin{align*}I_1 &= \frac{1}{2\pi} \int_0^{\pi/4} \int_0^{2\pi} d_1(\theta, \varphi) \,d\varphi \, \sin \theta \,d\theta \\ &= \frac{1}{2\pi} \int_0^{\pi/4} \pi \tan \theta \, d\theta = \left.-\frac{1}{2} \ln | \cos \theta | \right|^{\pi/4}_0 \\ &= \frac{1}{4} \ln 2 \approx 0.17328679514\dots.\end{align*} In Region II, $$d_2(\theta, \varphi) = \frac{\csc \theta}{2} \min \{ |\sec \varphi|, |\csc \varphi| \},$$ so we have \begin{align*} I_2 &= \frac{1}{2\pi} \int_{\cos^{-1} (1/\sqrt{3})}^{\pi/2} \int_0^{2\pi} \frac{1}{2} \min \{ |\sec \varphi|, |\csc \varphi| \} \,d\varphi \csc \theta \sin \theta \,d\theta \\ &= \int_{\cos^{-1} (1/\sqrt{3})}^{\pi/2} \left( \frac{1}{2\pi} \int_0^{2\pi} \frac{1}{2} \min \{ |\sec \varphi|, |\csc \varphi| \} \,d\varphi \right) \,d\theta\\ & = \frac{2}{\pi} \ln ( 1 + \sqrt{2} ) \left( \frac{\pi}{2} - \cos^{-1} \left(\frac{1}{\sqrt{3}}\right) \right)\\ & = \left( 1 - \frac{ 2 \cos^{-1} \left( \frac{1}{\sqrt{3}} \right) }{\pi} \right) \ln (1 + \sqrt{2}) \approx 0.345345573653\dots,\end{align*} since the integral with respect to $\varphi$ is none other than the expected distance traveled inside a square, which we found the solution for in the Classic Problem. The trickier third region has integral $$I_3 = \int_{\pi/4}^{\cos^{-1} (1/\sqrt{3})} \int_0^{2\pi} d(\theta,\varphi) \,d\varphi \sin \theta \, d\theta \approx 0.0920550322989\dots,$$ which does not seem to have a readily available analytical solution. Putting these regions together we get that the overall average distance traveled to the surface of the unit cube when uniformly randomly choosing a direction is $$\hat{d} = I_1 + I_2 + I_3 = \frac{1}{4} \ln 2 + \left( 1 - \frac{ 2 \cos^{-1} \left( \frac{1}{\sqrt{3}} \right) }{\pi} \right) \ln (1 + \sqrt{2}) + I_3 \approx 0.610687401568\dots.$$