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: 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: References: Date: Tue, 15 Apr 2014 17:07:50 -0700 Subject: Re: random.seed question (not reproducing same sequence) From: Dan Stromberg To: Nick Mellor Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 wrot= e: > Hi guys, > > (Python 2.7, Windows 7 64-bit) > > Here's a bit of code stress-testing a method addUpdate_special_to_cart. T= he 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=3D=3D4,= once with special_qty=3D=3D0, reseeding the Python random module number ge= nerator to a fixed seed (a string) between the iterations. special_qty=3D= =3D0 removes the special and restocks the products. The test relies on prec= isely 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 pa= sses. > > 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=3Dcart, stockbin= =3Drandrange(test_size), > special_id=3Drandrang= e(test_size), special_qty=3Dqty, > products=3D[(random.c= hoice(PRODUCTS), random.choice(range(10))) > for r in range(ra= ndrange(7))]) > -- > https://mail.python.org/mailman/listinfo/python-list