Code improvement: united random generation in the start and after a successful match