Interactively fill in skyscrapers. Drag the slider to fill in the landscape:

This is the code to make a landscape with 30 skyscrapers:

Out[1]= | |

You can make the landscape interactive with Manipulate.

Manipulate attaches interactive controls to things like this expression for 3 squared:

Out[2]= | |

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:

Out[3]= | |

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:

Out[4]= | |

The buildings jump around because RandomReal gives different numbers each time it is used. You can make them stay put by adding SeedRandom[12345] to the code:

Out[5]= | |

Here’s why SeedRandom[12345] 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[12345] 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:

Out[6]= | |

This list of random numbers is always the same because the random number generator is reset with SeedRandom:

Out[7]= | |

You can give different numbers to SeedRandom to reset the random number generator to different places.