“Second Ending” is one of my own favorite stories, and not just because it was voted onto the short list of five novels for the 1963 Hugo award (Heinlein’s Stranger in a Strange Land, a much longer, and better, story, won it that year). So strongly did I feel about the story that when it was submitted to my favorite editor and he requested a few changes — including a reduction in length to twenty thousand words and the introduction of a surviving island of humanity! — I demurred. It was the only time in my writing career that I said “No” to an editor in such forthright language. After close on a quarter of a century in the game, I have now learned how to make all my “No’s” sound like “Well, maybe’s.”
Returning to the original question, “Where on Earth do you get those crazy ideas from?”, it seems that in my case they come from unfulfilled ambitions, feelings of injustice, meeting a bedraggled dog or a beautiful girl, or from a friend with polluted pants. But the simple answer is that all of the ideas have a solidly terrestrial origin, and so the question answers itself.