checking randomness



how do i generate a number in a set with a probability 'P'?
is the following approach correct: out of "N' itrations choose that
number 'P' times (randomly though) .

.