Random order of table

Random order of table

Postby Marc Vanzegbroeck » Tue Jan 26, 2010 9:12 am

Hi,

I have create a little program with exercises for childeren.
I have a table with the exercises.
I want each time I start the program re-order the complete table in an new random order. How can I do this?

Thanks,
Marc
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Random order of table

Postby James Bott » Tue Jan 26, 2010 6:13 pm

Marc,

FW has a function nRandom(nRange) which you could use.

The issue is that you want a list of random numbers and you don't want any of them repeated. So, I would use an array and use DO WHILE to keep adding random numbers until the array is full. Each time you generate a new number you have to check the array to see if the number already exists. If so, then generate a new number. If not, then add the number.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Random order of table

Postby Marc Vanzegbroeck » Tue Jan 26, 2010 6:26 pm

James,

Thanks for pointing me to the direction. I'm gona add a field in the database,and fill it with a random-number generated with nRandom().
Then I will index the database on that field.

Regards,
Marc
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Random order of table

Postby James Bott » Tue Jan 26, 2010 6:53 pm

Marc,

Well, that should work, but it would be faster to generate an array and use the numbers in the array as recno's. This method would not require any disk writes or indexes.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 56 guests

cron