Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

random.setstate(getstate()) can't restore the state of generator to what it was at the time getstate() was called #580

Closed
ironpythonbot opened this issue Dec 9, 2014 · 0 comments
Labels

Comments

@ironpythonbot
Copy link

ironpythonbot commented Dec 9, 2014

In the below code, two results of "[a.random() for i in xrange(10)]" should be
same:

E:\2.5test\ironpythonCompatableFor2.5\25\Lib>ipy  
IronPython console: IronPython 2.0A5 (2.0.11011.00) on .NET 2.0.50727.42  
Copyright (c) Microsoft Corporation. All rights reserved.  

>>> import random  
a = random.Random()  
a.seed()  
state = a.getstate()  
[a.random() for i in xrange(10)]  
[0.0606536218248, 0.227661377856, 0.383911680143, 0.0532521740781,
0.64292679896  
7, 0.626307238651, 0.583549570564, 0.294446938808, 0.777077497345,
0.693130396629]  
a.setstate(state)  
[a.random() for i in xrange(10)]  
[0.296399478939, 0.512523207121, 0.643615922725, 0.0341588538299,
0.415964689765  
, 0.108518776534, 0.686661085899, 0.505765370329, 0.971637266675,
0.706592465614  
]  

Two result in Cpython 2.5 are same:

E:\2.5test\ironpythonCompatableFor2.5\25\Lib>python  
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on
win  
32  
Type "help", "copyright", "credits" or "license" for more information.  
import random  
a = random.Random()  
a.seed()  
state = a.getstate()  
[a.random() for i in xrange(10)]  
[0.29828293888054935, 0.0088578084426363946, 0.6956068877658238,
0.60082415615727158, 0.024660010547330358, 0.93204550535867003,
0.18639283049196298, 0.88948524149415675, 0.14358934586660388,
0.43360810573501363]  
a.setstate(state)  
[a.random() for i in xrange(10)]  
[0.29828293888054935, 0.0088578084426363946, 0.6956068877658238,
0.60082415615727158, 0.024660010547330358, 0.93204550535867003,
0.18639283049196298, 0.88948524149415675, 0.14358934586660388,
0.43360810573501363]  
import random  
a = random.Random()  
a.seed()  
state = a.getstate()  
[a.random() for i in xrange(10)]  
a.setstate(state)  
[a.random() for i in xrange(10)]  

Work Item Details

Original CodePlex Issue: Issue 23820
Status: Active
Reason Closed: Unassigned
Assigned to: Unassigned
Reported on: Jul 27, 2009 at 11:57 PM
Reported by: dfugate
Updated on: Feb 22, 2013 at 2:12 AM
Updated by: jdhardy
Custom value: Reported internally at Microsoft.
Test: test_random.py
CreatedDate: 11/6/2007
NewInternalID: 409627
OldInternalID: 319175
AreaPath: IronPython\Modules

@slide slide removed the untriaged label Oct 22, 2016
slide added a commit that referenced this issue Oct 23, 2016
test_random is still not passing though
@slide slide added the 2.7.7 label Oct 24, 2016
slide added a commit that referenced this issue Oct 24, 2016
* Fix #278, #581, #577, #580

test_random is still not passing though

* Reduce using LINQ

* Update based on feedback from @slozier

Swap objects in the print
@slide slide closed this as completed Oct 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants