I am trying to use the following code to obtain random samples according to custom distribution, but Mathematica is very often not able to give it in reasonable time. One random sample takes either between 0,015-0,05 seconds or it runs without the result for more than one minute at which point I stop the calculation.
The forum dropped stars between the numbers and hats so in the expression of the polynom there is
0.00008027261407746941 x^4 - 2.592723712534534 * 10^-7 x^5 +3.4947822352866564` * 10^-10 x^6
It would be better to edit your original question to put in the missing characters and use the formatting tools. You might also want to add in what you mean by “too slow”.
I suspect that the issue is that of “round off error” because of the large numbers involved (such as 145^6 = 9294114390625) when an attempt (internally) is made to match a uniform random number to an approximation of the cumulative distribution function. (Maybe scaling things using Horner’s scheme might be helpful to reduce the round-off error.)
One approximation to get around this is to generate a list of values for the cumulative distribution function (with the associated values of DA) and then use interpolation. One can make the approximation more accurate but at the expense of more time creating the interpolation table. Here’s an example:
Good. I wish I knew what the exact problem is. (I get the same symptoms for your density: first random sample seems to work but then stalls forever for any subsequent random samples.)