Custom rng function kumarasuamy regression

How can I specify similar to the code below so that now considering the kumarasuamy distribution ? I believe it is necessary to implement the kumarasuamy_rng function, how can I proceed?

Or rather, how to generalize to any distribution that does not have an accumulated distribution function with a closed expression?

generated quantities {
  vector[N] y_rep;
  for (i in 1:N) { 
    real mu;
    real A;
    real B;
    mu = inv_logit(X[i] * beta);   
    A = mu * phi;
    B = (1.0 - mu) * phi;
    y_rep[i] = beta_rng(A, B); 

Kumaraswamy has a simple inverse cdf, so one option is to use uniform_rng and then transform to Kumaraswamy using the inverse cdf:

If u ~ uniform(0,1) and k = (1 – (1 – u*)^(1/b))^(1/a), then k ~ Kumaraswamy(a,b).

But definitely check that I got the inverse cdf right: Kumaraswamy distribution: a beta-like probability density


R Code for a Kumaraswami brms family (including an rng) is available in bayesfam