How to draw samples from a user-defined distribution without writing _rng function

I have implemented a multivariate distribution in stan by writing a function ending with ‘_lpdf’, however, the distribution may be too complex and I have not been able to find a suitable way to implement the ‘_rng’ function. How can I sample from this distribution without writing the _rng function? Can I use the following method?

functions{
real mydistribution_lpdf(vector x){
      ...}
}
parameters {
vector[10] newsample;

(other statements to define parameters in the model);
}

model{
mysamples~mydistribution();
target -=mydistribution_lpdf(newsample);

(other statements to define the model/log-likelihood);

}

No. In fact, newsample will be used along with the “true” parameters and make the join posterior less accurate.

The _rng functions are intended to output exact, uncorrelated samples. If correlated samples are sufficient for your application then you can use Stan to generate correlated samples with Markov chain Monte Carlo, although not in the way you suggest.

If you write

functions{
  real mydistribution_lpdf(vector x){
      ...}
}
parameters {
  vector[10] x;
}

model{
  target += mydistribution_lpdf(x);
}

and run Stan then by default you’ll get four sequences of 1000 correlated samples for the 10-dimensional variable x. You can then use these correlated samples as desired, for example as simulated data to be input into another Stan program that implements a posterior distribution.

Depending on the structure of mydistribution_lpdf the correlation might be very strong or very weak, and you’ll be responsible for ensuring that they’re well enough behaved for you application.