It triiiiies to replace the weapon with the least ammo, but it's a little bugged. Because the Rail Gun has a Max ammo of 20 or so and others have a max of 100, the Rail gun will often be immediately replaced! Boo indeed!
If I go back to it, it needs to replace weapons based on relative remaining ammo rather than absolute.