Re: Random select?

2009-04-06 Thread Henrik Sarvell
Thanks Alex, will try it out!


On Mon, Apr 6, 2009 at 7:30 AM, Alexander Burger  wrot=
e:
> Hi Henrik,
>
>> Imagine having thousands of articles in a database, AFAIK using
>> collect to get them all and then getting a random subsection would not
>> be the best solution as the process would eat up a lot of memory.
>
> You could use 'maxKey' to get the highest key in the database, and then
> use 'rand' repeatedly to find objects with 'db':
>
> =A0 (let Max (maxKey (tree 'aid '+Article))
> =A0 =A0 =A0(do 100
> =A0 =A0 =A0 =A0 (until (db 'aid '+Article (rand 1 Max)))
> =A0 =A0 =A0 =A0 (printsp @) ) )
>
> Cheers,
> - Alex
> --
> UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=3dunsubscribe
>
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe


Re: Random select?

2009-04-05 Thread Alexander Burger
Hi Henrik,

> Imagine having thousands of articles in a database, AFAIK using
> collect to get them all and then getting a random subsection would not
> be the best solution as the process would eat up a lot of memory.

You could use 'maxKey' to get the highest key in the database, and then
use 'rand' repeatedly to find objects with 'db':

   (let Max (maxKey (tree 'aid '+Article))
  (do 100
 (until (db 'aid '+Article (rand 1 Max)))
 (printsp @) ) )

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe