[Zope] How to get 4 Random DTML Documents

Dylan Reinhardt zope at dylanreinhardt.com
Sat Nov 8 14:32:25 EST 2003


On Sat, 2003-11-08 at 11:12, Martin Koekenberg wrote:
> Hello,
> 
> That is a solution but  that gives me 4 random links an not set of 4 random
> links without double entry's.

Ah... that's a different question.  :-)

For this, I'd ditch DTML and move to Python Scripts.

I'd use two scripts, one to generate random links and one that ensures
that you have exactly four non-duplicating ones.  I suppose you could
also do this recursively, but I try to avoid being tricky with Python
Scripts.  :-)

Doing this, your controller script will look something like:

-----
my_pages = {}
while 1:
    rnd_page = context.other_script()
    if not my_pages.has_key(rnd_page):
        my_pages[rnd_page] = 1
    if len(my_pages) > 3:
        break
return my_pages.keys()
-----

The above is totally untested, but should be close enough to move you
forward.

HTH,

Dylan





More information about the Zope mailing list