random.seed question (not reproducing same sequence)
John Gordon
gordon at panix.com
Wed Apr 16 00:32:57 EDT 2014
In <bc918afe-4b20-46c2-ab86-de0ea3c8d456 at googlegroups.com> Nick Mellor <thebalancepro at gmail.com> writes:
> In response to your question, John, all I know is that my own code doesn't
> use the random module outside of this code fragment.
Does addUpdate_special_to_cart() use any random methods?
In any case, a further test would be to strip out all the business logic
and leave only the calls to random, and see if the results still differ.
Something like this:
rnd = random.Random()
for qty in [4, 0]:
print "qty is %s" % qty
rnd.seed(seed)
print "seed is %s" % seed
for cart in range(test_size):
print "cart is %s " % cart
for special in range(rnd.randrange(3)):
print "special is %s " % special
print "stockbin is %s" % rnd.randrange(test_size)
print "special_id is %s" % rnd.randrange(test_size)
print "products is %s" % [(rnd.choice(PRODUCTS), rnd.choice(range(10))) for r in range(rnd.randrange(7))])
Run that code sample and see if the results differ when qty is 4 vs 0.
--
John Gordon Imagine what it must be like for a real medical doctor to
gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'.
More information about the Python-list
mailing list