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)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; '(python': 0.07; 'assign': 0.07; 'removes': 0.07; 'subject:same': 0.07; 'occasionally': 0.09; 'subject:question': 0.10; 'cc:addr :python-list': 0.11; 'python': 0.11; 'random': 0.14; 'windows': 0.15; 'afterwards': 0.16; 'cc:name:python list': 0.16; 'guys,': 0.16; 'iterates': 0.16; 'nick': 0.16; 'string)': 0.16; 'sync': 0.16; 'url:py': 0.16; 'url:svn': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'module': 0.19; 'cc:addr:python.org': 0.22; 'adds': 0.24; 'passes': 0.24; 'cc:2**0': 0.24; '15,': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'fixed': 0.29; 'skip:p 30': 0.29; 'am,': 0.29; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'lot.': 0.31; 'relies': 0.31; 'url:python': 0.33; 'could': 0.34; 'subject: (': 0.35; 'anywhere': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'executing': 0.36; 'sequence': 0.36; 'wishes,': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'should': 0.36; 'wrong': 0.37; 'two': 0.37; 'level': 0.37; 'easily': 0.37; 'stock': 0.39; 'url:mail': 0.40; 'provide': 0.64; 'to:addr:gmail.com': 0.65; 'between': 0.67; 'products': 0.71; 'products.': 0.72; 'special': 0.74; 'darn': 0.84; 'shopping': 0.87
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=ejUYT2uUJD3TIwgPdrr5jZB+f8dEU+YSiZXEMOc+FX4=; b=L/R1XpFcgTRIpzRqb6ToJUfWpp1mwjwnxN/8ilMK9qoYYMNUt6PNflRChPfQn9HrqY lKQoCCtN6Y3gvjn8dZ1IA/5GmgNEWlwK/e8rZY1N40WZRgvEZJ9VZsg6I5x2OGpfKRxg UVR1I0PAEvLnHK4rpkvF91ceGWvzqVGUyP8HlVbYtwysegouStsPiCCT7DVq0NsUoSMQ D07dTncqqZsmXIbV3uAyW38iifcKodNxdGefc7dgw4K1gkVCyqdUQ6okIdQIDYYrkujr yR5JihsCp/vDMfkCissohpBMG8Q/CIDimjlvTiDe2B9swsfacOvUwzJ92w56gxxdbAej IkLw==
MIME-Version 1.0
X-Received by 10.180.11.239 with SMTP id t15mr4754228wib.25.1397606871017; Tue, 15 Apr 2014 17:07:51 -0700 (PDT)
In-Reply-To <e452de11-1615-4869-8c2a-c2e78a96357c@googlegroups.com>
References <e452de11-1615-4869-8c2a-c2e78a96357c@googlegroups.com>
Date Tue, 15 Apr 2014 17:07:50 -0700
Subject Re: random.seed question (not reproducing same sequence)
From Dan Stromberg <drsalists@gmail.com>
To Nick Mellor <thebalancepro@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9306.1397606872.18130.python-list@python.org> (permalink)
Lines 57
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1397606872 news.xs4all.nl 2842 [2001:888:2000:d::a6]:50156
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70305

Show key headers only | 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