Epsilon: random()-random() gets simplified to 0

Created on 5 Oct 2018  Β·  7Comments  Β·  Source: numworks/epsilon

When trying to simulate throwing two dice I stumbled across this:
randint(1,6)+randint(1,6) gets simplified to 2*randint(1,6)

That does not yield the expected result of two individual dice being thrown, but instead of one dice being thrown and counted twice, which is a huge difference.

This also happens in other places, e.g. in Sequences where one might want to visualize a distribution of values when throwing a certain number of dice.

I propose that random integers should be treated as always different so they won't be combined when simplifying the term

runtime-bug

Most helpful comment

like random()-random() which always gets simplified to 0

Are you sure? Maybe you were just (un)lucky? πŸ˜„

All 7 comments

This also extends to something like random()-random() which always gets simplified to 0

That's a good catch πŸ˜„

like random()-random() which always gets simplified to 0

Are you sure? Maybe you were just (un)lucky? πŸ˜„

β€œThe generation of random numbers is too important to be left to chance.”
--forgot who

like random()-random() which always gets simplified to 0

Are you sure? Maybe you were just (un)lucky? πŸ˜„

That reminds me that getRandomNumber() would be a funny easter egg
https://xkcd.com/221/

This has been fixed in 210ec62 πŸ˜„

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriweb picture adriweb  Β·  4Comments

boricj picture boricj  Β·  4Comments

0b101 picture 0b101  Β·  5Comments

homeostasie picture homeostasie  Β·  3Comments

TheElectronWill picture TheElectronWill  Β·  3Comments