functions to sample c