Let a and b, with a < b, be two level sites of a general random walk. If we partition the interval [a, b] into n arbitrary subintervals with endpoints a < a_1 < a_2 < · · · <a_(n-1)< b, then the hitting time from a to b can also be decomposed by the hitting times between adjacent pairs of sites. As the walk moves back and forth between these endpoints, loops are created. Hence, we can express the generating function of the hitting time as a loop decomposition for an arbitrary number of consecutive sites. By applying this decomposition to a 1-dimensional reflected Brownian motion with equally distributed sites, we can then derive identities of Bernoulli and Euler polynomials in terms of their higher-order generalizations. Similar results from a 3-dimensional Bessel process can also be obtained.