上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
TSAISUN
註冊時間: 2006-02-12 文章: 12
第 1 樓
|
發表於: 星期三 一月 17, 2007 9:51 pm 文章主題: 請問如何亂數拉出十筆記錄 |
|
|
一個dbf,裡面有100題測驗題,每個學生測驗題目,都由亂數產生任十題,也就是說,順序或題目,不一定相同
新手問題,請問那個先進,教幾段程式
誠摯的感謝您們 |
|
回頂端 |
|
 |
saint
註冊時間: 2003-07-14 文章: 211
第 2 樓
|
發表於: 星期四 一月 18, 2007 12:01 am 文章主題: |
|
|
所以就是要100選十,選過不能再選!
local ln_len as Integer,ln_count as Integer,ln_test_pos as Integer,ll_find as Boolean
ln_count = 10 &&要產生出來的題目
ln_len = 100 &&總題數
dimension la_tested[ln_count]
dimension test[ln_len]
for i=1 to ln_len
test[i] = i
next
for i=1 to ln_count
la_tested[i] = 0
next
local ln_test_loop as Integer
ln_test_loop = 1
do while .t.
ln_test_pos = ln_len + 1
do while ln_test_pos > ln_len
ln_test_pos = getRand()
enddo
for g = 1 to ln_count
if la_tested[g] == 0 then
for x=1 to ln_count
if la_tested[x] == ln_test_pos then
ll_find = .t.
exit
endif
next
if not ll_find then
wait window str(ln_test_loop)+ ":" + str(ln_test_pos) timeout 1
ll_find = .f.
la_tested[ln_test_loop ] = ln_test_pos
ln_test_loop = ln_test_loop + 1
exit
endif
endif
next
if ln_test_loop == 11 then
exit
endif
enddo
*------
function getRand()
local ln_rand as Integer
ln_rand = 0
do while ln_rand < 1
ln_rand = rand(0) * 100
enddo
return int(ln_rand) + 1
endfunc |
|
回頂端 |
|
 |
garfield Site Admin

註冊時間: 2003-01-30 文章: 2160
第 3 樓
|
發表於: 星期四 一月 18, 2007 1:27 pm 文章主題: |
|
|
寫作業時間到了.
出題( 10 ) &&--出10題
func 出題
lpara mcount
sele 題庫
總題數=recc()
dime 出題[總題數]
for i=1 to 總題數
出題[i]=i
next
* 從頭到尾打亂順序
for i=1 to 總題數
swapos = int(rand()*總題數)+1 &&--測試過 rand() 出現的亂數會比rand(0) 均勻
mtemp = 出題[i]
出題[i]= 出題[swapos]
出題[swapos] = mtemp
next
* 取出前面 mcount 筆題
for i=1 to mcount
go 出題[i]
? 出題[i], 顯示欄位資料
next _________________ 利用>>搜尋<<的功能會比問的還要快得到答案. |
|
回頂端 |
|
 |
marvin
註冊時間: 2004-06-01 文章: 321
第 4 樓
|
發表於: 星期四 一月 18, 2007 2:03 pm 文章主題: |
|
|
所以說只要作業題目好, 高手們還是會賞光的. |
|
回頂端 |
|
 |
小賴
註冊時間: 2004-12-27 文章: 476
第 5 樓
|
發表於: 星期四 一月 18, 2007 2:39 pm 文章主題: |
|
|
湊一下熱鬧 :
SELECT TOP 10 RAND() AS FRand, * FROM 題庫 ORDER BY 1 |
|
回頂端 |
|
 |
syntech
註冊時間: 2003-05-16 文章: 4249 來自: Taipei,Taiwan
第 6 樓
|
發表於: 星期四 一月 18, 2007 3:03 pm 文章主題: |
|
|
我習慣用 剪刀及漿糊 _________________ 如果公司有下列困擾:
1. 找不到便宜,快速,簡易的 生產排程軟體
2. 不知道如何快速排定 採購計劃
3. 成本抓不準,自己算比軟體算有用
4. 想學習系統規劃,想找系統架構的顧問
請聯絡我們,也許我們幫得上忙 |
|
回頂端 |
|
 |
garfield Site Admin

註冊時間: 2003-01-30 文章: 2160
第 7 樓
|
發表於: 星期四 一月 18, 2007 6:29 pm 文章主題: |
|
|
小賴兄才是高手啊, 一行程式就解決問題.
不過用 "洗八辣" 也不錯, 快過年咩! _________________ 利用>>搜尋<<的功能會比問的還要快得到答案. |
|
回頂端 |
|
 |
saint
註冊時間: 2003-07-14 文章: 211
第 8 樓
|
發表於: 星期五 一月 19, 2007 10:33 pm 文章主題: |
|
|
的確是!一行就可以解決!不過,我看到時就有想到一個問題,就是有可能會重復!如果你的電腦夠快,多執行幾次,就會發現..Orz |
|
回頂端 |
|
 |
KKKLYNN
註冊時間: 2004-09-17 文章: 357
第 9 樓
|
發表於: 星期三 一月 24, 2007 9:41 am 文章主題: |
|
|
我也來試試
先宣告陣列
varray=int(100*rand())
gPos = ASCAN(garray,varray) && 搜索值
若存在則重新給值
滿十題後就依陣列內的值,從題庫取出題目
因為剛剛要寫個尾牙binggo遊戲卡,相同類別
以上您參考 |
|
回頂端 |
|
 |
|