Masturbation, Biblically speaking
I would suggest reading Leviticus 15:16-18 in several different translations. I rather prefer ESV in this instance. Note that verses 16 and 17 are conjoined by the word 'And', then 17 ends with a period. 18 begins a new situation. I am nobody's expert, and I absolutely do NOT wish to lead anyone astray, but it certainly appears that the 'spilling of seed' (ejaculation) solo and in the act of intercourse with a woman are two separate acts.
As for 'onanism', please read Genesis 38:6-10, paying special attention to verse 9, again in several translations. "The sin of Onan" has NOTHING to do with masturbation. As pointed out in other threads, Onan refused to impregnate his brother's widow as was the required custom. Quite apparently he had sex with her (Tamar) on multiple occasions but 'pulled out' (coitus interruptus) before ejaculating, thereby spilling his seed on the ground. That was the sin of Onan.
[Note: read all of chapter 38-- it gets REALLY interesting after this !!]
So, is masturbation a sin ? What about having lust in your mind, etc.? Pray about it (everything really). What is the Holy Spirit speaking to YOU? GOD bless.