@zsoroaszter I just have one that kind of fits nicely on my head, i pull it down to almost cover my eyes, and the back of the beanie fits the back of my head well, down to where my hair ends. I think just having a nice fit is key, if your beanie is too small then it will inevitably fall off in the middle of the night.
Or perhaps you just move too much when you sleep, and in that case I would recommend trying the string thing.