C program to sample input given some probability