随机双色球,6个红球,范围在1到33,取随机数。1个篮球,范围在1到16,取一个随机数。会验证同一组中红球随机数不会重复。- $count = @()
- $item = @()
- $max = 33
- $min = 1
-
- # 创建Excel应用
- Write-Verbose "Creating Excel application"
- $xl=New-Object -ComObject "Excel.Application"
- $wb=$xl.Workbooks.Add()
- $ws=$wb.Worksheets.Add()
- $cells=$ws.Cells
-
- #定义输出范围
- $row=3
- $col=1
-
- "Red1","Red2","Red3","Red4","Red5","Red6",“Blue” | foreach {
- $cells.item($row,$col)=$_
- $cells.item($row,$col).font.bold=$True
- $col++
- }
-
- #循环生成随机数,写入excel
- for($j=1;$j -le 5;$j++)
- {
- $row++
- $col=1
- for($i=1; $i -le 6; $i++)
- {
- $b = Get-Random -Minimum $min -Maximum $max
- $bl=$count.Contains($b)
- while($bl){
- $b = Get-Random -Minimum $min -Maximum $max
- $bl=$count.Contains($b)
- }
- $count += $b
-
- $cells.item($Row,$col) = $b
- $col++
- }
-
- $cells.item($Row,$col) = Get-Random -Minimum 1 -Maximum 16
-
-
- }
-
- #现实并关闭,你可以点取消,查看最后效果
- #make Excel visible
- $xl.Visible=$True
- $xl.Quit()
复制代码
|