The O'Reilly Python Cookbook gives a couple of interesting approaches-- 2.8 Selecting random elements from a list without repetition 4.5 Retrieving a line at randome from a file of unknown size On 8 Nov 2003, Dylan Reinhardt wrote:
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
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )