Sampling from a distribution: Where to find the basics

Part of my project requires that I do some sampling and although I can find some answers, i find my questions to be rather basic ( like sampling from a truncated normal or sampling from a marginal distribution). I could find answers here, but I feel that it should be easy to find an answer to such questions in a book, but it seems that there is no such thing. I can't find any theory properly written!

My question is, can I find such a book/ pdf lecture, and if yes, where :)?

Edit: Some context to better understand my question:

A couple days ago, I wondered how to sample from a marginal distribution $f_X(x) = \int f(x|y) f(y) dy$, I asked around, got an answer, but they weren't able to explain why it worked ( sample from y plug y in the conditional, keep the x) , and it sort of makes sense but i can't justify it, and it happened to me before that when it comes to sampling, no one can give much more than recipes. And i would like to know where i can find how to "prove" it.

Thank you :)

• It's not really clear to me what specifically you are interested in. Are you interested in inverse transform sampling? Or in software implementations? Can you please clarify? – Stephan Kolassa Oct 16 '17 at 7:54
• Ok, well, couple days ago, I wondered how to sample from a marginal distribution $f_X(x) = \int f(x|y)f(y)dy$, I asked around, got an answer, but they weren't able to explain why it worked ( sample from y plug y in the conditional, keep the x) , and it sort of makes sense but i can't justify it, and it happened to me before that when it comes to sampling, no one can give much more than recipes. And i would like to know where i can find how to "prove" it. Thank you :) – Max C Oct 16 '17 at 8:05
• Thanks! Could you please edit that information into the question? That would make it a lot easier to answer. (And comments are ephemeral.) – Stephan Kolassa Oct 16 '17 at 8:20
• I have edited my question – Max C Oct 16 '17 at 8:28
• A good book is "Simulation" from Sheldon Ross. Chapters 3, 4 and 5 explain all about generating random numbers. – StijnDeVuyst Oct 16 '17 at 9:15