Updated function "sample_val"