In this paper the problem of global optimization of magnetic structures composed of solenoids is faced, using a modified Simulated Annealing algorithm able to deal with the functions of continuous and/or discrete variables. The algorithm is tested using a discrete problem which allows determination of the cost function for every possible configuration of the system, providing information about the pattern of the cost function with respect to design variables. Despite the difficulty of minimizing the function, the proposed algorithm was able to locate the global minimum, or a point where the cost function has a value very close to it, seven times out of a total of ten runs. The algorithm used is described and results are presented and discussed.