Artificial intelligent assistant

Weighted random sample over continuous data I'm attempting to write an algorithm which gives a random value x in the domain [0-1) and is weighted according to a function. I don't seem to be able to determine how to do this with continuous data, but the problem seems quite trivial with discrete weights/options. Extra information: The algorithm generating the evenly-weighted random number between 0 and 1 is abstracted away, what I'm attempting to do is shift said random point. After many samples, the resulting distribution of samples should match the function being used to shift the random values.

If you can integrate $w(x)$ to give $W(x)=\int_0^x w(y)$ and then find an inverse of $W(x)$, you could chose your weighted random value to be $$W^{-1}\left(x\,W(1) \right)$$

If the calculations for that are too difficult then another approach, assuming that the weighting function $w(x)$ is bounded above by some known constant $b$, one approach might be:

1. Generate two uniform random numbers $x$ and $y$ on $[0,1)$

2. If $y \le \dfrac{w(x)}{b}$ then accept $x$ as the random value; otherwise repeat steps $1$ and $2$




The inefficiency of this algorithm depends on the relationship between $b$ and the expected value of $w(x)$

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 69c1b9304b89087669b9aed2b741707f