arrays - 有什么方法可以改善此Powershell阵列随机播放方法吗?

标签 arrays powershell random

我开发了一个纸牌组来在Visio上玩棋盘游戏,但是我和我的 friend 们对纸牌的“感觉”并不好。

我使用的代码如下(我简化了代码,但我对包含数字的卡片的正字使用相同的算法,如果需要,我可以添加它):

    # Actions
    $CONFIG_ACTIONS = @{
        "pool"=9
        "interim"=9
        "bis"=9
        "parc"=18
        "sell"=18
        "barrier"=18
    }
    $unshuffeledListAction = [System.Collections.ArrayList]@()
    foreach ($actionToAdd in $CONFIG_ACTIONS.Keys) {
        [int]$howManyTime = $($CONFIG_ACTIONS[$actionToAdd])
        for($i=0;$i -lt $howManyTime;$i++) {
            $unshuffeledListAction.Add($actionToAdd) | out-null
        }
    }
    # Request random number between 0 and 65535
    $requestURI = "https://qrng.anu.edu.au/API/jsonI.php?length=1&type=uint16"
    # Randomize Cards: Try WebService
    Try {
        $random = $(Invoke-RestMethod -Uri $requestURI -Method GET).data 
        $shuffeledListActions = $unshuffeledListAction | Get-Random -Count $unshuffeledListAction.Count -SetSeed ($random[0])       
    } Catch {
        Write-warning "Failed to called QRNG@ANU JSON API switching to local pseudo-random"
        $shuffeledListActions = $unshuffeledListAction | Get-Random -Count $unshuffeledListAction.Count
    }

我对安全性没有特殊需求,因为这是供个人使用而没有敏感信息,因此我可以使用WebServices,并且已经尝试过。

我的第一次洗牌尝试很简单:
$shuffeledListActions = $unshuffeledListAction | Get-Random -Count $unshuffeledListAction.Count

可以改善吗?调用量子随机数生成器服务的第二次尝试是否更好?

最佳答案

Get-Random -Count很好。我可能会完全放弃Web服务调用。 PRNG非常好,从其他地方获取种子不会在这里发生太大变化。

关于arrays - 有什么方法可以改善此Powershell阵列随机播放方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61558941/

相关文章:

c - 将用户输入放入字符数组(C 编程)

php - 如何在 PHP/MYSQL 中从数组获取 Int 结果

powershell - DPM-Powershell脚本获取可用于备份的文件列表

r - 如何创建有偏随机数生成器?

python - 如何在python中生成8字节唯一随机数?

c++ - 如何在 C++ 中访问数组结构内部的数组结构?

c# - 具有多个值的 ArrayList c#

powershell - 通过 Powershell 创建 Azure 流分析作业

powershell - -Verbose 不适用于 PowerShell 中的 Pester 测试

c++ - 使用特征向量中的权重从离散分布中采样