Implementing custom distributions and prior from scratch

For parameters \theta and observations x,

P(\theta \mid x) = P(x \mid \theta) P(\theta) / P (x)

When I implement custom random variables, should I set the Hamiltonian as the following?

H(\theta) = \exp\lbrace -\ln[(P(x \mid \theta)P(\theta)] \rbrace

And also draw the starting point according to the prior distribution P(\theta)?

Thanks again.