Get a random orthogonal matrix with elements of R

How can I get a random orthogonal matrix with elements of R in Sage?
If I understand the documentation correctly, GO(3,RR) contains all orthogonal matrices of dimension 3 with elements of R?
How can I get a random element from GO(3,RR)?

1 answer

Ideally, there should be a random_element method but it is not implemented (yet). There seems to be a number of algorithms out there, so if you plan to implement one, please consider contributing it into Sage !

If you do not really mind the density, you can just look at the QR-decomposition of a random real matrix (though this itself is not well defined):

If you mind having the density corresponding to the Haar measure, according to https://en.wikipedia.org/wiki/Orthogo... you can generate a real matrix with Gaussian entries such that the diagonal ones are positive: