*!* 功能:根据数组返回其中的n个内容的连接字符串
*!* 参数:
*!* taQueCode 数组的内容,引用方式调用
*!* tnQueCount 取多少个元素
*!* 返回值:
*!* 随机tnQueCount个元素的连接字符串,如果数组个数不够,返回全部数组连接字符串.
*!* 调用方式 to_getListCode(@laQuestion, 3)
*!* 修改记录: 2000.09.03 创建 天外闲人
select cQueID from tbQuestion into array laQuestion
if _tally <= 0
=messagebox('没有题目存在,无法进行考试!!')
return .f.
endif
Local lcGetCode &&题目编号字符串
lcGetCode = to_getListCode(@laQuestion, gn_queCount)
? lcGetCode
return
***********************************************************
#DEFINE RAND_SORT_COUNT 4 &&洗牌的次数
function to_getListCode
parameters taQueCode, tnQueCount &&考试题目数
external array taQueCode
dimension laQueCode[1]
acopy(taQueCode, laQueCode)
Local lcReturn, lnIndex
lcReturn = ''
*!* 如果题目数目少,直接返回!
lnACount = alen(laQueCode)
if tnQueCount >= lnACount
for lnIndex = 1 to lnACount
lcReturn = lcReturn + ' ' + laQueCode[lnIndex]
endfor
return lcReturn
endif
dimension laTemp[lnACount]
Local lnTemp01 &&临时变量,用于循环次数
Local lnRandAt &&洗牌的随机数
Local lnSkipCount &&取牌次数
Local lnStep &&洗牌次数
Local lnAtIndex &&进牌数组位置
for lnTemp01 = 1 to RAND_SORT_COUNT
lnRandAt = int(rand() * lnACount)
lnSkipCount = iif( lnRandAt >= (lnACount + 1)/2, lnRandAt, lnACount - lnRandAt)
lnAtIndex = 0
for lnStep = 0 to lnSkipCount - 1
if (lnRandAt - lnStep) > 0
lnAtIndex = lnAtIndex + 1
laTemp[lnAtIndex] = laQueCode[lnRandAt - lnStep]
* ? lnAtIndex
* ? laTemp[lnAtIndex]
endif
if (lnACount - lnStep) > lnRandAt
lnAtIndex = lnAtIndex + 1
laTemp[lnAtIndex] = laQueCode[lnACount - lnStep]
* ? lnAtIndex
* ? laTemp[lnAtIndex]
endif
endfor
acopy(laTemp, laQueCode)
endfor
lnBegin = int(rand() * lnACount)
for lnTemp = 1 to tnQueCount
lcReturn = lcReturn + ' ' + ;
iif(lnBegin + lnTemp > lnACount, ;
laQueCode[lnBegin + lnTemp - lnACount], ;
laQueCode[lnBegin + lnTemp])
endfor
return lcReturn
endfunc