The code is in a structured loop, but to mee it seems that there is a check if your image actually has a dimensions corresponding to the HOG window that is being used. If not, it will generate issues later down the line.
There is nothing random in it .... how do you come to that conclusion?
This is a specific setting of the SVM parameters ... the sample shows you how to adapt it, but for basic purposes you do not even need it.