2021-03-07【Math】Shuffle

2021-03-07  本文已影响0人  持刀的要迟到了

https://www.jianshu.com/p/762bf1c490a5

    public void Shuffle<T>(List<T> items)
    {
        //随机交换
        int currentIndex;
        T tempValue;      
        for (int i = items.Count - 1; i >= 0; i--)
        {
            currentIndex = rng.Range(i+1);
            tempValue = items[currentIndex];
            items[currentIndex] = items[i];
            items[i] = tempValue;
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读