It doen't work because the method document.write( )
does *NOT* return any value.
SO when you do
var randomNumber = document.write(Math.floor((Math.random()*5)+4));
indeed that writes the number to the screen, but then it assigns the result of calling document.write( )
to your variable. But, as I said, that result is non-existent, so you are assigning null
to your variable.
It is also true that you shouldn't depend on being able to set
of a <select>.