function x = random_obs(X, cpdf)

% x = random_obs(X, cpdf)
%
% return random element x of domain X, with cumulative density function cfdf.
% X, cpdf = [1, N]

% Liam Pedersen, May 1999, CMU.

N = length(X);
r = rand;

i = min(find(r <= cpdf));
x = X(i);