You are correct that doing this with Javascript is a hack. Doing this in PHP is the correct way.
When index includes header, it's as if header had been cut and pasted right into index. Same for banner. Therefore, any variables that are generated or calculated or looked up or whatever in banner will continue to exist for the rest of the execution of index.
I'm not sure how you're picking the random string from random.txt. Maybe you're picking a random number and reading that line? Whatever. However you pick that... just keep that in a variable. (For example, if you are picking a random number and then reading that line of text, just store the random number in $random or something).
Then, when you get to the point where you display the skyscraper, you can use the value of $random to know which company's skyscraper you should display. For example, if you have 3 companies, you might name their skyscraper images like this: skyscraper1.jpg, skyscraper2.jpg, skyscraper3.jpg. Since you know the value of $random, you can just say:
<img src="skyscraper<?php print "$random"; ?>.jpg">
Be sure not to screw up the line order of random.txt, though. If the order of the lines doesn't correlate with the image names of the skyscrapers, you won't see the right building.
I would do this in a database with the fields ID, HTML, IMAGE_NAME. This way, I would pick a random number, read that record, and I would always know that the HTML matches the image name I'm going to be displaying later in index.