This takes a specified 'tile' object and generates the grid based on it, I could have used just a flat plane or squashed cube for the tile, the script would run quicker, but I wanted it to have 'tabs' and grooves just like the real thing. It looks good, but the more verts the slower the script. You also have to set up the material beforehand, just to basically choose the texture, the script does the uv mapping.
The puzzle starts from the 'finished' position and the script animates each tile randomly to mix the puzzle. Keyframes are recorded in such a way that when played forward the animation appears to descramble as it goes on. There's also a few other things the script does such as printing out useful output to the console to show how far along the script has got, the final 30 x 30 grid at the end of the video takes a fair few minutes to create so it's nice to have progress reports. I also factored in that after you've run the script you'll often want to run it again but with different parameters, so the grid can also delete the old grid before creating the new one if you want.
This isn't going to be a beginner python tutorial or even a beginner python in blender tutorial, this is probably for people who've already made a few small scripts themselves using the blender api.