Your loop is happening once every frame. You need some event to make it happen only once. As oosyrag already stated, a mouse click, keyboard key pressed, or a button press.
Just FYI, floor(random(9))
will actually give you values between 0 - 8. Here's a quote from the manual regarding the Random system expression, "Generate a random float from 0 to x, not including x"