Non-deterministic output
Laurent Claessens
moky.math at gmail.com
Mon Mar 28 07:50:44 EDT 2011
> One of us thought it could be set and dictionaries not always yielding
> the same results. I, however, would think that given the exact same
> operations, a set/dictionary would always yield the same results. Am I
> correct? Or could different runs of the same program yield different
> results due to, say, different memory locations?
If you have
d={"a":1,"b":2}
print d.keys()
then there are no way to be deterministic.
What you can do is
d={"a":1,"b":2}
k = d.keys()
k.sort()
print k
This is deterministic.
An other source of non-deterministic behaviour is to rely on the 15th
decimal of a difficult computation.
I had the following with Sage[1] :
sage: p=plot(x**2,-1,1)
sage: p.get_minmax_data()
{'xmin': -1.0, 'ymin': 3.0448943892610684e-06, 'ymax': 1.0, 'xmax': 1.0}
and in a new Sage shell :
sage: p=plot(x**2,-1,1)
sage: p.get_minmax_data()
{'xmin': -1.0, 'ymin': 1.2545281288559271e-05, 'ymax': 1.0, 'xmax': 1.0}
Hope it helps
Laurent
[1] www.sagemath.org
More information about the Python-list
mailing list