标题: [原创代码] 随机双色球PowerShell脚本 [打印本页]
作者: Brightblade 时间: 2014-3-10 11:11 标题: 随机双色球PowerShell脚本
随机双色球,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()
复制代码
作者: Brightblade 时间: 2014-3-12 10:12
感觉自选组一多,结果就会变慢。还得再改一改
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |