For a standard Brownian motion $\omega(t)$ in $R^p, p \geq 3$, let $t_a(\omega)$ be the last exit time from the ball $B(0, a)$ of radius $a$ centered at the origin and let $F(a, t, \omega)$ be the oscillation in the neighbourhood of sphere $S(0, a)$. The distribution of the functional $B_f(a, \omega) = \int^{+\infty}_0 1_{B(0,a)}(\omega(t))f\big(\frac{F(a, t, \omega)}{F(a, +\infty, \omega)}\big) dt,$ where $f: (0, 1) \rightarrow R^+$ is an arbitrary bounded measurable function, coincides with the limiting distribution, when $n \rightarrow +\infty$, of the weighted sojourn time $\frac{T_f(a\sqrt n, \omega)}{n} = \sum^{+\infty}_{k=0} 1_{B(0,a\sqrt n)}(S_k(\omega))f\big(\frac{n(a\sqrt n, k, \omega)}{n(a\sqrt n, +\infty, \omega)}\big)\big/n$ for a standard random walk in $Z^p$ where $n(b, k, \omega)$ denote the number of crossing $S(0, b)$ during the first $k$ steps. We give explicit formulas, in terms of Laplace transform, for the joint distribution of $B_f(a, \omega), F(a, +\infty, \omega)$ and $t_a(\omega)$.