Math.random() returns the same value over and over

Check out this notebook for an example. I’m not sure of the mechanism behind it, but it’s interesting and does impose certain limitations on demoing random outcomes. It seems like the first function never repeats, but the second function will repeat if you run it over and over - though occasionally it will shift to a different result.

You are experiencing time traveling. When you re-run the second cell, we rewind the state of the machine to before it was run, and then re-run it. As such, random values will be the same. However, from the first cell, you are starting from scratch. Imagine that you had done a lot of work in the first cell, you wouldn’t want to re-run the document from scratch, you would just want to continue from the last “save point”. If you want “another” random value, you can simply do it in another cell (this allows you to keep re-running the same experiment). There is more explanation here: