Generation of quasiequally spaced ultrashort microbunches in a photocathode rf gun