Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70305

Re: random.seed question (not reproducing same sequence)

References <e452de11-1615-4869-8c2a-c2e78a96357c@googlegroups.com>
Date 2014-04-15 17:07 -0700
Subject Re: random.seed question (not reproducing same sequence)
From Dan Stromberg <drsalists@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.9306.1397606872.18130.python-list@python.org> (permalink)

Show all headers | View raw


You could easily provide your own random number generator, if you
don't need cryptographic-strength random numbers.

EG:
http://stromberg.dnsalias.org/svn/lcgrng/trunk/lcgrng.py

That way you can be certain nothing else is using it.


On Tue, Apr 15, 2014 at 8:54 AM, Nick Mellor <thebalancepro@gmail.com> wrote:
> Hi guys,
>
> (Python 2.7, Windows 7 64-bit)
>
> Here's a bit of code stress-testing a method addUpdate_special_to_cart. The test adds and updates random "specials" (multiple products bundled at an advantageous price) of various sizes to thousands of shopping carts, then restocks the whole darn lot. The test passes if the stock level afterwards is the same as it was before executing the code for all products.
>
> addUpdate_special_to_cart is working perfectly. But the test isn't.
>
> The test iterates over the same code twice, once with special_qty==4, once with special_qty==0, reseeding the Python random module number generator to a fixed seed (a string) between the iterations. special_qty==0 removes the special and restocks the products. The test relies on precisely the same random number sequence on both runs.
>
> Can you think of a reason why the random number generator should fall out of sync between the two iterations? Because that's what's happening by the look of it: occasionally products are returned to the wrong stockbin. No "random" module method is used anywhere else while this code is executing.
>
> When I assign something non-random to the stockbin parameter, the test passes.
>
> Best wishes,
>
>
>
> Nick
>
> for qty in [4, 0]:
>                 random.seed(seed)
>                 for cart in range(test_size):
>                     for special in range(randrange(3)):
>                         s.addUpdate_special_to_cart(cart=cart, stockbin=randrange(test_size),
>                                                     special_id=randrange(test_size), special_qty=qty,
>                                                     products=[(random.choice(PRODUCTS), random.choice(range(10)))
>                                                         for r in range(randrange(7))])
> --
> https://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

random.seed question (not reproducing same sequence) Nick Mellor <thebalancepro@gmail.com> - 2014-04-15 08:54 -0700
  Re: random.seed question (not reproducing same sequence) John Gordon <gordon@panix.com> - 2014-04-15 16:21 +0000
    Re: random.seed question (not reproducing same sequence) Nick Mellor <thebalancepro@gmail.com> - 2014-04-15 18:05 -0700
      Re: random.seed question (not reproducing same sequence) John Gordon <gordon@panix.com> - 2014-04-16 04:32 +0000
  Re: random.seed question (not reproducing same sequence) Ned Batchelder <ned@nedbatchelder.com> - 2014-04-15 12:36 -0400
  Re: random.seed question (not reproducing same sequence) Peter Otten <__peter__@web.de> - 2014-04-15 19:34 +0200
  Re: random.seed question (not reproducing same sequence) Dan Stromberg <drsalists@gmail.com> - 2014-04-15 17:07 -0700
  Re: random.seed question (not reproducing same sequence) Ned Batchelder <ned@nedbatchelder.com> - 2014-04-15 20:48 -0400

csiph-web