How to generate a random sample and distribute values based in an probability distribution? I want to generate a random sample based on this probability distribution:

The line is the KDE of the histogram.
My random sample will have n values, the value is a number of points. Each of the n values generates an amount of points p that must be distributed among the population. So I must distribute the total of n * p points. The distribution of points must follow the probability distribution above.
How should I generate a random sample that follow this probability distribution?
Probably this is a usual problem, so I welcome any help to better formulate my question.
Create some random data
df &lt;- data.frame(
  cat_cols = c(rep(&quot;A&quot;, 200), rep(&quot;B&quot;,150)),
  cont_vals = c(rnorm(200, 20, 5), rnorm(150,25,10)))
# Set desired binwidth and number of non-missing obs
bw = 2
n_obs = sum(!is.na(df$cont_vals))

Now plot it
library(ggplot2)
ggplot(df, aes(cont_vals))  + 
  geom_histogram(aes(y = ..density..), binwidth = bw, colour = &quot;black&quot;) + 
  stat_function(fun = dnorm, args = list(mean = mean(df$cont_vals), sd = sd(df$cont_vals)))