Sampling from Gaussian Processes: A Tutorial and Applications in Global Sensitivity Analysis and Optimization