FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Random order of table
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Random order of table
Posted: Tue Jan 26, 2010 09: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Random order of table
Posted: Tue Jan 26, 2010 06: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Random order of table
Posted: Tue Jan 26, 2010 06: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Random order of table
Posted: Tue Jan 26, 2010 06: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion