using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CardGen : MonoBehaviour { public Text[] txtR; int[] CNum = new int[16]; // Use this for initialization void Start () { int i, j; genRnd (0, 15, 16); for (i = 0; i < 16; i++) txtR [i].text = CNum [i].ToString(); } // Update is called once per frame void Update () { } //產生不重複隨機亂數 public void genRnd(int min, int max, int takeOut) { int total = max - min + 1; int remain = total; int[] t = new int[total]; int i = 0; int j = 0; for (i = 0; i < total; i++) { t[i] = min + i; } for (i = 0; i < takeOut; i++) { int temp = (int)Random.Range(0, remain); Debug.Log(temp.ToString() + " " + t[temp].ToString()); //int temp = Mathf.Floor(Random.Range(0,1)*remain) + 1; CNum[i] = t[temp]; //this["data" + i] = this["t" + temp]; for (j = temp; j < (remain - 1); j++) { t[j] = t[j + 1]; } remain--; } } }