Instead of trying 3 times before using time(), why not just use a while loop?