Given a normalized vector N, how can one generate a random direction vector that is guaranteed to be in the hemisphere with respect to N (i.e. the hemisphere where N is exactly in the middle)? The way I am currently doing this is to sample a random direction vector d and dot it with N and keep that vector if the dot product is greater than 0. This method is not guaranteed to generate a vector in the hemisphere that I am interested in as ~50% of the random vectors would have a 0 or negative dot product result.
I saw somewhere that there is a way to transform the randomly generated vector d to place it in the right hemisphere using a transformation matrix but I don't know how to do it. Can someone write a [pseudo]code for how one generate a direction vector using the transformation method?
In this case, you can just randomly generate $d$, and if it does not lie in the right hemisphere, because $d \cdot N < 0$, replace $d$ by $-d$.