1樓:匿名使用者
private sub command1_click()
dim i as long, n as long, y as long, x as long, a() as integer
y = list1.listcount
n = val(text1.text) '獲取輸入的數量,text1可以自己改
if n < 1 then exit sub '輸入數量不能為0
if y < n then exit sub '抽取數量不能為大於已經存在姓名列表
randomize
for i = 0 to n - 1
x = int((y - 1 + 1) * rnd + 1) '隨生成機數字
redim preserve a(i)
a(i) = x
for j = 0 to ubound(a) - 1
if x = a(j) then i = i - 1: exit for '判斷是否重複
next
next
for i = 0 to ubound(a)
list2.additem list1.list(a(i)) 'list1內抽取到的新增到list2,右邊的 list1 和 list2 自己改
next
end sub
2樓:匿名使用者
先判斷已經抽取的結果,如果存在重新抽取。
用VB程式設計隨機抽取姓名,用vb編寫了這個隨機抽取人名的程式,要求一個文字框,一個按鈕
60個人的記錄,把隨機函式控制成小於等於60 private type student name as string 10 end type private sub command1 click 寫入資料dim stu as student open d student.txt for random...
用哪個函式可以隨機抽取集合中的元素
要生成隨機數就要使用rand函式和randbetween函式,前者生成小於1的函式,後者生成二個約束數字間的函式 用excel隨機抽樣用什麼函式? a1輸入 rand 向下填充至 a24 b1輸入 rank a1,a 1 a 24 向下填充至b24 b列就會出現一個1 24數字的隨機分佈 b1 b9...
怎樣用ecel軟體做隨機分組,怎樣用excel軟體做隨機分組
簡淨軒語 可以使用rand函式生成隨機序號,然後再按照隨機序號分組。在想要分組的資料旁邊使用輔助列,列標題為隨機序號,並輸入公式 round rand 10 1 1,這樣每一條記錄都有一個隨機序號,然後再通過篩選或者資料透視表的方法實現分組。需要提醒的是,rand函式為隨機數,按下f9會重新整理資料...