Appropriate ordering of magnet pieces in a wiggler can reduce the wiggler field errors and therefore simplify measurement and adjustment procedures which must be taken to reduce them. We applied a genetic algorithm to this optimization problem, that is, determination of the sequence of permanent magnet pieces in a wiggler. Wigglers with small field errors can be designed by this method within a reasonable calculation time even for the case of thousands of magnet pieces. Using appropriate fitness functions, both dipole errors and rms errors of a wiggler can be minimized and the field correction after assembling of the wiggler can be greatly simplified.