I don’t think anyone considers them evil as such. However, the key part of this quote:
it’s easier to determine how widgets behave
Obviously, Math.random()
introduces indeterminism, so you can never be sure how the code will behave on every run.
What is not obvious is that Date
brings a similar indeterminism. If your code somehow depends on the current date, it (obviously, obviously) will work differently in some conditions.
I think it is not surprising that these two methods / objects are non-functional, in other words, each run can return different results regardless of the arguments.
In general, there are several ways to combat this indeterminism. Storing the initial random seed to reproduce the exact same series of random numbers (not possible in JavaScript) and providing the client code as if it were an abstraction of TimeProvider
instead of letting it create a Date
everywhere.
source share