It is legal syntax. If it is not compiling it is because there is an error somewhere that you have not provided code for.
I am not sure what you are trying to achieve, though, because the same randNumber is being assigned to all your variables. Your loop generates the number a few times but overwrites the variable with each new number.