TITLE: Time to end of a random duration - Convergence in distribution to a uniform distribution?
QUESTION [2 upvotes]: Edit: The numeric experiments that led to this question are wrong. I have left the question here because the answer from @Vincent was interesting and informative. Please also see other answer as to where I went wrong.
Let $B$ be a continuous, non-negative random variable with infinite support and let $\mu_B = \mathrm{E}(B)$ be the mean of $B$.
Let $Z$ be uniformly distributed on the interval $[0,B]$, and $W = B-Z$. (Intuition: $B$ is a period when someone is busy, $Z$ is the arrival of an interruption, $W$ is the time to wait until that interruption  will be serviced.)

Conjecture. As $\mu_B \to \infty$, $W$ converges in distribution to a uniform distribution on $[0,\mu_B]$.

(Edit: Thank you @Vincent who pointed out that I should have conjectured that $W/\mu_B$ converges in distribution to a uniform distribution on $[0,1]$. I have left the conjecture as-is for reference.)
I arrived at the conjecture from experiments; I have included examples and Python code below. But is it true? (Or under what conditions?)
Remark: My underlying motivation is from queueing theory. I have a system that alternates between busy periods and idle periods (or the generalization to periods of congestion versus intercongestion). If an event occurs when the system is busy, how long until it becomes idle? Or likewise if an event occurs when the system is idle, how long until it becomes busy?
Heuristic argument
(Inserted as update after initial post)
Let $f(x)$ be the probability density function for $B$ and $h(w)$ be the probability density function for $W$. Then a little bit of work (see below) establishes that
$$
  h'(w) = -\frac{ f(w) }{ w }
$$
So postulate that under certain conditions, there exists $c_B$ such that if $0 < w < c_B$ then $f(w) \approx 0$ and hence $h'(w) \approx 0$. This accounts for an approximately-uniform distribution over $[0,c_B]$.
Moreover, further conjecture that in some circumstances, the distribution of $B$ can be changed to make $c_B$ bigger.
The mean $\mu_B = \mathrm{E}(B)$ of $B$ would appear to be a proxy for $c_B$ in some cases, though the conditions under which this is sufficient are not apparently obvious. Likewise, the necessary conditions for creating $c_B$ are not apparently obvious.
Proof that $h'(w) = -\frac{ f(w) }{ w }$.  Tile the positive reals into intervals of width $\delta x$ and put $x_k = k \cdot \delta x$ for $k = 1, 2, \dots$.  Then
$$\begin{align*}
\mathrm{P}(W=w) &= \sum_k \mathrm{P}(W=w|B=x_k)\cdot\mathrm{P}(B=x_k)
\\
&= \lim_{\delta x \to 0} \sum_{k=\lfloor w/\delta x \rfloor}^{\infty} \frac{1}{x_k} f(x) \, \delta x
\end{align*}$$
and hence
$$\begin{align*}
  h(w) &= \int_{w}^{\infty} \frac{ f(x) }{ x } \, dx
\\
       &= \int_{0}^{\infty} \frac{ f(x) }{ x } \, dx - \int_{0}^{w} \frac{ f(x) }{ x } \, dx
\end{align*}$$
Differentiating both sides yields the required result. $\blacksquare$
Examples
Histogram of wait times $W$ compared with the probability density function for the uniform distribution on $[0,\mu_B]$.

$B$ has an exponential distribution
$B$ has an exponential distribution" />

$B$ has a Rayleigh distribution
$B$ has a Rayleigh distribution" />

$B$ has a gamma distribution
$B$ has a gamma distribution" />

$B$ has a triangle distribution. It fails the condition of having infinite support, and the wait times do not appear to be uniformly distributed.
$B$ has a triangle distribution" />


Software
(Edit: This software is wrong. Please see answer.)
Python 3.7.6, Spyder 4.0.1
# Distribution of time to the end of durations.

import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import uniform
# from scipy.stats import expon
# from scipy.stats import rayleigh
# from scipy.stats import lognorm
# from scipy.stats import triang
# from scipy.stats import gamma
# from scipy.stats import fatiguelife
from scipy.stats import rice
# from scipy.stats import chi
# from scipy.stats import chi2
# from scipy.stats import weibull_min
# from scipy.stats import pareto
# from scipy.stats import powerlognorm
# from scipy.stats import alpha
# from scipy.stats import semicircular

# Durations yielding wait times that appear to be uniformly distributed.
# rvDuration = expon(47.1)
# rvDuration = rayleigh(7)
# rvDuration = lognorm(1.5, 335)  # Use loc to increase the mean.
# rvDuration = gamma(233)
# rvDuration = fatiguelife(0.4, 14)  # Use loc to increase the mean.
rvDuration = rice(17.7)
# rvDuration = chi(114)
# rvDuration = chi2(7551)
# rvDuration = weibull_min(18)
# rvDuration = pareto(35.1)
# rvDuration = powerlognorm(222.14, 0.446)
# rvDuration = alpha(3.57, 0, 15.6)  # But mean is infinite ?

# Durations yielding wait times that do not appear to be uniformly distributed.
# rvDuration = uniform(11, 12.6)  # Note loc, scale parametrization
# rvDuration = triang(0.7, 0, 1225)  # Use scale to increase the mean.
# rvDuration = semicircular(55, 55)  # Use scale and loc to increase mean.

countSamples = 80000

fig, ax = plt.subplots(1, 1)

# Sample of durations.
Binterval = rvDuration.rvs(size=countSamples)

# Sample the interruptions.
Zinterrupt = uniform.rvs(0, Binterval)

# Get wait times.
Wwaitout = Binterval - Zinterrupt

# Plot histogram of the wait durations.
ax.hist(Wwaitout, bins='auto', density=True, alpha=0.2)

# Plot a pdf - conjecture is that it is approximately uniform from
# zero to the mean of distribution for the intervals.
meanBinterval = rvDuration.mean()
if not math.isinf(meanBinterval):
    x = np.linspace(0, meanBinterval*1.2)
    ax.plot(x, uniform(0, meanBinterval).pdf(x), 'r-', lw=2, alpha=0.6)
plt.title('Distribution of times to the end of random durations' + '\n' +
          str(rvDuration.dist))
plt.xlabel('Wait time')
plt.ylabel('Density')

plt.show()

REPLY [0 votes]: The numeric experiments that led to the question were wrong. I misunderstood the calling syntax for random variable generators in Python.
The code
rvDuration = expon(15)

creates a  rvDuration as a random variable with exponential distribution of mean 1, then shifted to the right so that its location   (loc parameter) is 15.  What I should have called is
rvDuration = expon(scale=15)

to get an exponential distribution that is scaled to have mean 15 (scale parameter).
Minimal working example
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import expon

fig, ax = plt.subplots(1, 1)

# Intention: Exponential distribution with mean mu = 15.
mu = 15

# Wrong calling syntax for what was intended.
rvWrong = expon(15)

# Correct calling syntax.
rvCorrect = expon(scale=15)

# Compare the pdf.
x = np.linspace(rvWrong.ppf(0.01), rvWrong.ppf(0.99), 100)
ax.plot(x, rvWrong.pdf(x), 'r-', lw=2, alpha=0.6)
x = np.linspace(rvCorrect.ppf(0.01), rvCorrect.ppf(0.99), 100)
ax.plot(x, rvCorrect.pdf(x), 'b-', lw=2, alpha=0.6)

plt.show()
{"set_name": "stack_exchange", "score": 2, "question_id": 3866463}