C#獲取不同的隨機數
public static int GetRandomRangeNoRe2(int x, int y, int[] array = null) { if (array == null) { return UnityEngine.Random.Range(x, y); } else { List<int> list = new List<int>(); for (int i = x; i < y; i++) { list.Add(i); } List<int> aList = new List<int>(array); list.RemoveAll(m => m == aList.Find(n => n == m)); int z = UnityEngine.Random.Range(0, list.Count); return list[z]; } }
沒啥技術含量,實際就是把要過濾的數也傳進去。
然后在區間內,過濾掉對應的數,再隨機一次。
這個只處理int型。
小時候我把老婆種到地下,長大了我能收獲一大堆老婆!
我是威少,我是一名Unity游戲的主程,我為自己帶鹽,希望此文能給您一點點微不足道的幫助,祝你成功!

浙公網安備 33010602011771號