This map is adapted from Mike Bostock's world map with random colors. I implement an alternative algorithm for colouring the countries.
The principle for Mikes's coloring is:
- Take an ordered list of 10 colors
 - Take a region and assign it the first color (blue) by default
 - If the regions has neighbors, find out which is the highest ranked one in the list, and take the next one, which then necessarily different
 - Repeat until all regions are filled
 
Here's what you get:
This method works well for a world map but it has a few drawbacks:
- All regions with no neighbors (i.e. islands: Greenland, Iceland, Japan, Australia...) get colored in blue whereas it would be more pleasant that they come in various colors
 - The first colors in the list get to dominate the map and some (grey) are virtually unused.
 - It is not obvious on the world map, but Mike's method may use a very high number of colors, clearly over 10! (In practice, the consequence is that his implementation loops back to the beginning of the color list so that adjacent regions may share colors.) Why is that so? Imagine a region with only one neighbor, colored after the last color in the list. Any colour but the last one can be used here, but Mike's method requires to take the color after the highest ranked color among neighbors. Since by hypothesis, this highest ranked color is already the last in the list, we have a problem.
 
My proposed algorithm goes like this:
- Take an ordered list of 3 colours
 - Take a region ; draw a random color from the list ; assign this color to that region by default
 - If the region has neighbors, find out which colours are already in use among them ; if all colours are used, push a new colour to the list and fill the current region with it ; if not, pick a random colour among the colours not in use
 - Repeat until all regions are filled
 
This algorithm can colour all the countries of the world map with between 6 and 7 colours.
- This algorithm does not cope with the dominance of one colour over the others. The colors added late to the list are clearly dominated.
 - Colors given to big states (Russia, China...) give the impression to prevail.
 - The number of colours changes randomly.
 - The colouring itself is random, which may be problematic in some cases.
 
You're welcome to suggest improvements!
This map shows the Natural Earth Admin 0 - Countries shapefile at 50m resolution. Converted to TopoJSON, only 140K gzipped. Each country is identified by its ISO 3166-1 numeric code.

