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.


Zope-Dev maillist - [EMAIL PROTECTED]
** No cross posts or HTML encoding! **
(Related lists - http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )

Reply via email to