After reading the replies, and thinking about the problem a little bit more, I think I can phrase it better (the replies really helped me to better understand it).
I need to draw one of, say, N elements in every request, in such a way that over many requests the drawing distribution will be uniform. It doesn't have to be random, though. This can be achieved either with a deterministic mechanism, or via a probabilistic one. So the state I was talking about could be simply an integer value. In the previous posts we discussed mostly deterministic mechanisms. I now realize that the major requirement from such a mechanism is that the actions of retrieving a value and incrementing it should be done in one atomic action (atomic across concurrent requests). It seems that due the way Django and FastCGI work, it is not easy to find a deterministic mechanism that will work and also perform well. (I think that I can use a dummy model and create and save a new instance whenever I need a new value, and use the instance id as the value, but it seems too costly). What I now think is that I shall look for a probabilistic mechanism. Perhaps, assuming requests come in a more or less uniform distribution over time, I can use the time of the request to generate my "random numbers". For example, take the modulo N (number of elements) of the absolute request time (say number of seconds elapsed since a fixed point in time). I may need to think more of the math here. I'd happily read any comments. Thank for all the replies, Amit * Marty Alchin <[EMAIL PROTECTED]> [2008-02-14 11:48 -0500]: > > On Thu, Feb 14, 2008 at 11:31 AM, Alex Koshelev <[EMAIL PROTECTED]> wrote: > > > > Look at idea behind this: > > http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser > > That will likely fail to work across multiple requests, due to > threading and/or multi-process issues. > > Better yet, check out this little gem: > http://www.djangoproject.com/documentation/cache/#the-low-level-cache-api > > -Gul > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

