Revelation uses forty-two months twice, at 11:2 for the trampling of the holy city and at 13:5 for the authority given to the beast. The same period appears in the book in two other forms, 1,260 days at 11:3 and 12:6, and a time, times and half a time at 12:14, and all three are three and a half years, half of seven. The half-seven is the point: an interrupted completeness, a period of trial that is by construction not allowed to run its full course. The figure is borrowed from Daniel 7:25 and 12:7.
Matthew 1:17 announces the genealogy of Jesus as three sets of fourteen generations, from Abraham to David, David to the exile, and the exile to the Messiah. Forty-two is the stated schema. The names as actually listed yield forty-one, because Jechoniah closes the second set and opens the third and is counted once in the text; Matthew also omits three Judahite kings who appear in 1 Chronicles. The arrangement is deliberate, fourteen is the gematria of David's name in Hebrew, and the arithmetic is subordinate to the design. Anyone quoting the forty-two generations should know that the list does not deliver them.
The number's modern fame is unrelated to any of this. In Douglas Adams's The Hitchhiker's Guide to the Galaxy, broadcast from 1978 and published in 1979, forty-two is the answer to the ultimate question of life, the universe and everything, delivered by a computer that has been thinking for seven and a half million years. Adams was asked repeatedly why he chose it and consistently said it was arbitrary: a small, ordinary, unassuming number. The elaborate explanations that circulate were all constructed afterwards by readers, which is precisely the behaviour the joke was about.