ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> zope-Dev
zope-Dev
[Zope-dev] product refresh and random number generation.
by Romain Slootmaekers other posts by this author
Jan 28 2003 11:31AM messages near this date
[Zope-dev] New Products can't included anymore in Zope !!!!! | Re: [Zope-dev] product refresh and random number generation.
hi,

I'm having problems with random number generation and product refreshes. 
To illustrate the problem, consider the following product code:

class RandomNumberGenerator(SimpleItem.SimpleItem):
     """
          ...
     """
     def __init__(self,id):
         "initialize an instance"
         self.id = id
         self.__random = Random(time.time())


     def next(self):
         """
              returns next random number.
         """
         return self.__random.random()


ok, this works but whenever the product is refreshed or the zope server 
restarts, the generator will start to generate the same sequence of 
numbers, which is not what I want.

I'm having trouble understanding what is happening:

since the object gets pumped up every request it would make sense
that you get the same random number if you lose some state from the 
internal random generator. But this isn't happening. You apparantly only 
lose state when the product is refreshed or when the zope server 
restarts. Could this be a cache effect ?

(I could, as a last resort seed the generator with the current time 
every request, but then, I lose all guarantees about the period for the 
random number generation)

any input appreciated.

Romain.



_______________________________________________
Zope-Dev maillist  -  Zope-Dev@[...].org
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )
Thread:
Romain Slootmaekers
Toby Dickenson

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved