Interactively fill in skyscrapers. Drag the slider to fill in the landscape:
This is the code to make a landscape with 30 skyscrapers:
You can make the landscape interactive with Manipulate.
Manipulate attaches interactive controls to things like this expression for 3 squared:
Make that expression interactive by wrapping it with Manipulate[...], replacing the 3 with n, and specifying that n goes from 0 to 30 in steps of 1. Drag the slider to see the squares of various numbers:
You can do the same thing with the skyscraper expression to make it interactive. Wrap it with Manipulate[...], replace the 30 with n, and specify that n goes from 0 to 30 in steps of 1. Drag the slider to see the number of buildings change:
The buildings jump around because RandomReal gives different numbers each time it is used. You can make them stay put by adding SeedRandom to the code:
Here’s why SeedRandom keeps the buildings from jumping around.
RandomReal gives a different number each time it is used, so each time a new landscape is drawn, the buildings are in different positions.
SeedRandom resets the random number generator so that subsequent uses of RandomReal give the same sequence of random numbers.
This list of random numbers changes each time you run the code:
This list of random numbers is always the same because the random number generator is reset with SeedRandom:
You can give different numbers to SeedRandom to reset the random number generator to different places.