*****新增‘no_’数值型字段****思路是随机打乱表的排序,然后再进行分配。打乱排序来自百度lys_zj大神,效率不高,但能满足要求。
SET SAFETY OFF
CLOSE ALL
CLEAR
USE stu ALIAS stu IN 0
SELECT stu
_kc=RECCOUNT()
public nA(_kc),nB(_kc)
for i=1 to _kc
nA(i)=i
next
ii=1
do while ii<=_kc
for i=1 to _kc
if rand()=0
if nA(i)>0
nB(ii)=nA(i)
nA(i)=0
ii=ii+1
endif
endif
next
i=1
ENDDO
FOR iii=1 to _kc
GOTO nB(iii)
REPLACE no_ with iii
NEXT
INDEX on no_ to px
SELECT 年级 FROM stu GROUP BY 年级,nj ORDER BY nj INTO ARRAY stu1
_n=ALEN(stu1)
FOR _i=1 TO _n
rs=0
@_i,5 say stu1(_i)+"考场人数:" get rs
read
IF rs=0
EXIT
ENDIF
SET FILTER TO 年级=stu1(_i)
ma=1
mb=1 &&两个变量
GO TOP
DO WHILE !EOF()
IF mb>rs
ma=ma+1
mb=1
ELSE
REPLACE kc WITH ma,考场 WITH ma
REPLACE zh WITH mb,座号 WITH zh
SKIP
mb=mb+1
ENDIF
ENDDO
ENDFOR
CLOSE ALL
SET SAFETY OFF
CLOSE ALL
CLEAR
USE stu ALIAS stu IN 0
SELECT stu
_kc=RECCOUNT()
public nA(_kc),nB(_kc)
for i=1 to _kc
nA(i)=i
next
ii=1
do while ii<=_kc
for i=1 to _kc
if rand()=0
if nA(i)>0
nB(ii)=nA(i)
nA(i)=0
ii=ii+1
endif
endif
next
i=1
ENDDO
FOR iii=1 to _kc
GOTO nB(iii)
REPLACE no_ with iii
NEXT
INDEX on no_ to px
SELECT 年级 FROM stu GROUP BY 年级,nj ORDER BY nj INTO ARRAY stu1
_n=ALEN(stu1)
FOR _i=1 TO _n
rs=0
@_i,5 say stu1(_i)+"考场人数:" get rs
read
IF rs=0
EXIT
ENDIF
SET FILTER TO 年级=stu1(_i)
ma=1
mb=1 &&两个变量
GO TOP
DO WHILE !EOF()
IF mb>rs
ma=ma+1
mb=1
ELSE
REPLACE kc WITH ma,考场 WITH ma
REPLACE zh WITH mb,座号 WITH zh
SKIP
mb=mb+1
ENDIF
ENDDO
ENDFOR
CLOSE ALL
[此贴子已经被作者于2017-11-7 07:37编辑过]