demo code of mex sampler