By generating the frequency domain Fourier coefficients and then transforming them to the time domain, the author is guaranteed to get a signal that starts and ends at the same value, because the transformation assumes it's a periodic signal and so the first and last values of the period must be the same.