vb 彩牛概率統計for Excel

2021-08-14 17:22:09 字數 4337 閱讀 4776

彩牛統計牛牛概率

主要計算牛一到牛牛和炸彈無牛在excel表中統計列舉的牌型概率。**如下,順便了解了下vb這門古老的語言。唯一感想就是自動對其功能很強。突然吹使我再溫習下**之美,要把**寫好,寫規範啊。路途遙遠啊。

dim n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, nn, nz as double

dim m, n, i, j, r1, r2, r3, r, c, color, zd, cc as long

public function gettype(row) as integer

c = 0

zd = 0

for r1 = 1 to 5 step 1

for r2 = 2 to 5 step 1

for r3 = 3 to 5 step 1

if r1 < r2 and r2 < r3 then

if (cells(row, r1 + 1) + cells(row, r2 + 1) + cells(row, r3 + 1)) mod 10 <> 0 then

else

c = 1

end if

end if

next r3

next r2

next r1

if (cells(row, 2) = cells(row, 3) and cells(row, 3) = cells(row, 4) and cells(row, 4) = cells(row, 5)) or (cells(row, 2) = cells(row, 3) and cells(row, 3) = cells(row, 4) and cells(row, 4) = cells(row, 6)) or (cells(row, 2) = cells(row, 3) and cells(row, 3) = cells(row, 5) and cells(row, 5) = cells(row, 6)) or (cells(row, 2) = cells(row, 4) and cells(row, 4) = cells(row, 5) and cells(row, 5) = cells(row, 6)) or (cells(row, 3) = cells(row, 4) and cells(row, 4) = cells(row, 5) and cells(row, 5) = cells(row, 6)) then

zd = 1

else

zd = 0

end if

if zd = 1 then

gettype = 11

else

if c = 0 then

gettype = 0

else

if (cells(row, 2) + cells(row, 3) + cells(row, 4) + cells(row, 5) + cells(row, 6)) mod 10 <> 0 then

gettype = (cells(row, 2) + cells(row, 3) + cells(row, 4) + cells(row, 5) + cells(row, 6)) mod 10

else

gettype = 10

end if

end if

end if

end function

public function setcolor(row, color)

for r1 = 1 to 5 step 1

cells(row, r1 + 1).interior.color = color

'rgb(255, 255, 255)

next r1

end function

public function clear()

range("h2") = ""

range("h3") = ""

range("i2") = ""

range("i3") = ""

range("j2") = ""

range("j3") = ""

n3 = n3 + 1

range("k2") = ""

range("k3") = ""

range("l2") = ""

range("l3") = ""

range("m2") = ""

range("m3") = ""

range("n2") = ""

range("n3") = ""

range("o2") = ""

range("o3") = ""

range("p2") = ""

range("p3") = ""

range("q2") = ""

range("q3") = ""

range("r2") = ""

range("r3") = ""

range("s2") = ""

range("s3") = ""

range("g2") = ""

range("g3") = ""

end function

sub calculate()

n0 = 0

n1 = 0

n2 = 0

n3 = 0

n4 = 0

n5 = 0

n6 = 0

n7 = 0

n8 = 0

n9 = 0

nn = 0

nz = 0

cc = clear()

'range("t3") = (cells(1, 2) + cells(1, 3) + cells(1, 4) + cells(1, 5) + cells(1, 6)) mod 10

m = range("t2")

for j = 1 to m step 1

n = gettype(j)

select case n

case 0

n0 = n0 + 1

range("h2") = n0 / m

range("h3") = n0

color = setcolor(j, rgb(0, 0, 255))

case 1

n1 = n1 + 1

range("i2") = n1 / m

range("i3") = n1

case 2

n2 = n2 + 1

range("j2") = n2 / m

range("j3") = n2

case 3

n3 = n3 + 1

range("k2") = n3 / m

range("k3") = n3

case 4

n4 = n4 + 1

range("l2") = n4 / m

range("l3") = n4

case 5

n5 = n5 + 1

range("m2") = n5 / m

range("m3") = n5

case 6

n6 = n6 + 1

range("n2") = n6 / m

range("n3") = n6

case 7

n7 = n7 + 1

range("o2") = n7 / m

range("o3") = n7

case 8

n8 = n8 + 1

range("p2") = n8 / m

range("p3") = n8

case 9

n9 = n9 + 1

range("q2") = n9 / m

range("q3") = n9

case 10

nn = nn + 1

range("r2") = nn / m

range("r3") = nn

color = setcolor(j, rgb(0, 255, 0))

case 11

nz = nz + 1

range("s2") = nz / m

range("s3") = nz

color = setcolor(j, rgb(255, 0, 0))

end select

next j

range("g2") = (n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + nn + nz - 1) / m

range("g3") = (n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + nn + nz - 1)

end sub

MATLAB概率統計

一 產生隨機變數 二項分布隨機資料產生 n1 10 10 60 a1 binornd n1,1.n1 b1 binornd n1,1.n1,1,6 一行六列 c1 binornd n1 n1 1.n1 1.n1 2,6 兩行六列 正態分佈隨機資料產生 a2 normrnd 0,1,1,5 標準正態分...

223 概率統計

現象 特點概念 樣本空間s 樣本點w 複雜事件 隨機事件 分類事件間的關係 互斥事件 ab 差事件對立事件 積事件和事件 對立事件和互斥事件間關係 兩事件獨立性 定理一 事件a b獨立的充要條件 定理二推廣 計算時間的運算滿足的規律 事件的概率和頻率 概率性質 特殊的概率 定義性質 計算乘法公式 全...

VB字元統計函式

在 通用宣告 區宣告 窗體 模組級變數 option explicit dim letters as integer 宣告模組級變數,此變數計算字母個數 dim space as integer 空格個數 dim digit as integer 數字個數 dim others as integer...