Whether you lose on move 1 or move 2 due to bad luck is not a big difference
A simple algorithm would be to re-do the map generation until there is no mine collision, but with larger numbers of mines, the collision chance increases, so your runtime will go up superlinearly. A simple but very effective improvement is to keep the positions of the mines up until the collision and then only change the seed for subsequent mines. Then your algorithm should in fact scale much better. You can also use different methods, like assigning indices in a certain way so that invalid states are avoided completely. A bit more complicated but way "cleaner".
It happens so fast behind the scenes that the user isn't aware of it, and it makes sure I won't have to guess anything when I play. Purely skill, no random.
I feel like you've forgotten the purpose of a hobby.