The code looks fine, only the logic hast some drawbacks for example if you already have 5 sudokus in the path, you will have to execute your code 5 times before the creation is completed, don-t you think it will be better use a timestamp generated according the execution time and that is less possible get two repeated at the same time?