Re: [Zope] How to get 4 Random DTML Documents
Hello, That is a solution but that gives me 4 random links an not set of 4 random links without double entry's. Martin Koekenberg P.S. I unsubscribed me from zope-dev... I've nothing to do there. Just start to developing in Zope not Developing zope ;-) ----- Original Message ----- From: "Dylan Reinhardt" <zope@dylanreinhardt.com> To: "Martin Koekenberg" <zope@digital-adventures.nl> Sent: Saturday, November 08, 2003 7:37 PM Subject: Re: [Zope] How to get 4 Random DTML Documents
On Sat, 2003-11-08 at 10:30, Martin Koekenberg wrote:
Hello, With "<dtml-with expr="_.whrandom.choice(links.objectValues('DTML Document'))">" I can gert a radom DTML Dotument.
But how can I et 4 random documents with a probely a <dtml-in size =4....... statement ?
<dtml-in "_.range(4)">
And please don't send this kind of question to zope-dev.
HTH,
Dylan
Put your logic into a PythonScript where you fill up a list of n entries. You should be able to program this with 3-4 lines of code if you know how to program in Python. -aj --On Samstag, 8. November 2003 20:12 Uhr +0100 Martin Koekenberg <zope@digital-adventures.nl> wrote:
Hello,
That is a solution but that gives me 4 random links an not set of 4 random links without double entry's.
Martin Koekenberg
P.S. I unsubscribed me from zope-dev... I've nothing to do there. Just start to developing in Zope not Developing zope ;-)
----- Original Message ----- From: "Dylan Reinhardt" <zope@dylanreinhardt.com> To: "Martin Koekenberg" <zope@digital-adventures.nl> Sent: Saturday, November 08, 2003 7:37 PM Subject: Re: [Zope] How to get 4 Random DTML Documents
On Sat, 2003-11-08 at 10:30, Martin Koekenberg wrote:
Hello, With "<dtml-with expr="_.whrandom.choice(links.objectValues('DTML Document'))">" I can gert a radom DTML Dotument.
But how can I et 4 random documents with a probely a <dtml-in size =4....... statement ?
<dtml-in "_.range(4)">
And please don't send this kind of question to zope-dev.
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 )
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
On Sat, 2003-11-08 at 11:32, Dylan Reinhardt wrote:
----- 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() -----
Here's a better version: --- my_pages = {} i = 0 while len(my_pages) < 4 and i < 100: i += 1 rnd_page = context.other_script() if not my_pages.has_key(rnd_page): my_pages[rnd_page] = 1 return my_pages.keys() --- This eliminates the risk of huge loop problems caused by several predicable problems and is better style besides. HTH, Dylan
also sprach Dylan Reinhardt <zope@dylanreinhardt.com> [2003.11.08.2043 +0100]:
This eliminates the risk of huge loop problems caused by several predicable problems and is better style besides.
make a list of the available pages, then pop the item at four random indices off, one after the other. probably the most efficient and safe way. -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! micro$oft could shit in a box, and most people would buy it.
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 )
participants (5)
-
Andreas Jung -
Dennis Allison -
Dylan Reinhardt -
martin f krafft -
Martin Koekenberg