Yes, a gasoline or diesel portable generator will work. However, noise is an issue. Depending on how much current you need, using an inverter and charging with an engine alternator is another way to get AC current. It depends on the kind of boat, auxillary power, etc. Maybe you already know this.
Remember, the noise a generator makes is not only an annoyance for you but for everyone else in an anchorage. Some portables have better sound insulating properties, but usually come with a price.