Problem this random seed()
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Mar 19 10:18:36 EDT 2013
On Tue, 19 Mar 2013 06:50:34 -0700, NZach wrote:
> Sorry, my previous reply was completely wrong. The time is initialized
> through the initialize() to 0. So, each time i call main() the
> simulation time is initialized to 0.
>
> I changed the code in order to print and check the values of
>
> G.Rnd.expovariate(MachineClass.SrvRate) and
> G.Rnd.expovariate(ArrivalClass.ArvRate)
>
> here is the code and the changes i made :
> http://codeviewer.org/view/code:30d8
>
> The values are not the same.
Why you think that they should be? They are using random values, of
course they will be different, until you reset the seed.
py> from random import expovariate, seed
py> seed(123)
py> [expovariate(1) for i in range(3)]
[2.949543607473089, 2.4397037404431217, 0.8983482559638]
py> [expovariate(1) for i in range(3)]
[2.2284035134067692, 0.10402931548508174, 3.2661334288222377]
py> seed(123) # reset the seed
py> [expovariate(1) for i in range(3)]
[2.949543607473089, 2.4397037404431217, 0.8983482559638]
In your case, you initialise the seed once, using:
class G:
Rnd = Random(12345)
so when you want to run the same results again, you have to call:
G.Rnd.seed(12345)
By the way, what is the purpose of class G?
Also, you import expovariate from the Random module, but never use it.
--
Steven
More information about the Python-list
mailing list