query a table with results in random order

Ruslan Zasukhin sunshine at public.kherson.ua
Fri Dec 21 01:18:15 CST 2007


On 21/12/07 12:35 AM, "Thorsten Hohage" <thohage at objectmanufactur.com>
wrote:

Hi All,

I'd do it in this way:

1) do query => get Cursor with N records

2) prepare in YOUR language (RB) array with random values from 1 to N.

Then just use this array in loop to get positions of cursor:

    for I = 1 to N
    {
        pos = arr[i]

        curs.pos = pos       // "now you have random record..."
    }

> I'm afraid that you alway get the data back in a generic or specific
> order.
> 
> So IMHO you've got four different options
> 
> a) When you're talking about a single user app, you can define a order
> column and update this column with new randoms and then do the select
> in a second step
> 
> b) Use a stored procedure
> 
> c) Use a temp table - perhaps even in a on-the-fly-in-memory db - and
> create their a pair of order column and recID. This is preferable
> because it's multi-user and you don't going to change permanently the
> db w/o any real need
> 
> d) Same strategy like c. But you request the list of recIDs first.
> Then you resort these recIDs and loop about this array to fetch the
> record by record in a reordered way. There might be better options,
> e.g. I would use a Dictionary in RB and do a full fetch, but I didn't
> know about Director.
> 
> 
> Keep in mind, that randoms are often NOT random!!!! There is some more
> or less fancy staff to produce "pseudo-random" numbers, but especially
> if this test is played again and again the order might be predictable.
> Perhaps someone of the engineers can jump in here and say a word about
> the quality of Valentina randoms.
> 
> On 2007-12-20, at 22:28, Czajka, Mark wrote:
> 
>> I want to query a database, but get the results back in a random order
>> for a testing application (randomize the order of the questions). I
>> have
>> the questions and their answers stored in a Valentina db/table and I'm
>> using Director. Could anyone provide some tips on how they would solve
>> this problem? Would this utlize a random cursor or some other
>> function.
>> Thanks for any help you could provide.

-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list