//create sample file for example clear close all if file('shuffle.dbf') // drop table shuffle endif if not file('shuffle.dbf') create table shuffle (id autoinc,name character(25), selected boolean,slow boolean) use shuffle for n = 65 to 84 append blank replace name with chr(n) next for n = 97 to 116 append blank replace name with chr(n) next go top for n = 1 to 19 replace selected with true skip 2 next go top for n = 1 to 5 replace slow with true replace name with trim(name) + ' ***' skip 4 next use endif ************************************************* ******* create tables for each day's matches i = random(-1) aDay1 = build_array() aDay2 = build_array() aDay3 = build_array() if file('matches.dbf') drop table matches endif if not file('matches.dbf') create table matches (id autoinc,name character(25),day_no int,; match int) q = new query() q.sql = 'select * from matches' q.active = true for nDay = 1 to 3 nMatch = 1 for n = 0 to 18 q.rowset.beginAppend() cmd = "q.rowset.fields['name'].value = aDay"+nDay+"[n+1]" ?cmd &cmd q.rowset.fields['day_no'].value = nDay if n%4 = 3 nMatch ++ endif q.rowset.fields['match'].value = nMatch next q.rowset.save() next q.active = false endif function build_array ***** Create an aray aPlayers1 for 14 normal players aPlayers1 = new array() q = new query() q.sql = 'select name from shuffle where selected = true and not slow = true' q.active = true do while not q.rowset.endofset aPlayers1.add(q.rowset.fields['name'].value) q.rowset.next() enddo q.active = false // if type('i') = 'U' // ?'i' // i = random(-1) //initlise random() by passing and argument. Only do this once. // endif for n = aPlayers1.size -1 to 1 step -1 do i = int(random()*15) until i>0 and i<15 ?i a1 = aPlayers1[n] a2 = aPlayers1[i] aPlayers1[n] = a2 aPlayers1[i] = a1 next ****** Create and array aPlayers2 for slow players aPlayers2 = new array() q = new query() q.sql = 'select name from shuffle where selected = true and slow = true' q.active = true do while not q.rowset.endofset aPlayers2.add(q.rowset.fields['name'].value) q.rowset.next() enddo q.active = false i = random(-1) for n = aPlayers2.size -1 to 1 step -1 do i = int(random()*6) until i>0 and i<6 a1 = aPlayers2[n] a2 = aPlayers2[i] aPlayers2[n] = a2 aPlayers2[i] = a1 next ******* Create an array aPlayers and interleave normal and slow players. **** Match 1 3 Ball 3 normal players **** Match 2,3,4 4 Ball 3 normal players 1 slow player **** Match 5 4 Ball 2 normal players 2 slow players // 1 X 3 ball, 4 X 4 ball i = 1 aPlayers = new array() for n = 1 to 6 aPlayers.add(aPlayers1[n]) next aPlayers.add(aPlayers2[i]) i ++ for n = 7 to 9 aPlayers.add(aPlayers1[n]) next aPlayers.add(aPlayers2[i]) i ++ for n = 10 to 12 aPlayers.add(aPlayers1[n]) next aPlayers.add(aPlayers2[i]) i ++ for n = 13 to 14 aPlayers.add(aPlayers1[n]) next aPlayers.add(aPlayers2[i]) i ++ aPlayers.add(aPlayers2[i]) return aPlayers