Simulated annealing (SA) is a probabilistic technique for approximating the global optimum of a given function. Specifically, it is a metaheuristic to approximate global optimization in a large search space.
Thought it may bring a crazy output, it will help you to understand the code on how to build one simulating annealing.