How does a generator produce an alternating current?