Not a bad mod by the looks of it thanks for contributing. Just some small things after a quick scan -
1) why do a query for the userdata? You already have $ir with everything in.
2) Some deprecated html in there e.g. <center>
3) you abs( (int)) numbers that come from rand(). There is no point as it's always going to be a number, and no user input seems to be able to manipulate it here.
4) I would suggest since you have the query there anyway, and nothing linking it to the user table indefinitely why not give it its own table? Called once, on one page but it's increasing your larger user query.