Generalized Fourier Series for Representing Random Variables and Application for Quantifying Uncertainties in Optimization