I am asked to generate a random matrix that satisfy the requirements for rotation matrices. Since I don't really know how to do that, I thought of creating a random quaternion(hopefully, there is no error there. If there is, please let me know). I start by randomizing an angle between 0 and 2$\pi$ and a vector $t$ (axis) . then I get the unit vector of t. Now I want to convert the quaternion to a rotation matrix. So is there a sample of code I could use to do so? Anyhow, Thanks!
rg=2*pi*[0,1]; theta=diff(rg)*rand(1,1)+rg(1); t=rand(3,1)*2-1; q = [cos(theta/2),t(1)* sin(theta/2),t(2)* sin(theta/2),t(3)* sin(theta/2)]; R = zeros(3);