抽取不同的随机数

            Random r = new Random();           

            int[] ab = new int[6];
            //下面是在1-7随机抽取不同数加入ab[]数组中
            for (int k = 0; k < 6; k++)
            {
            AA:
                int b = Convert.ToInt32(r.Next(1, 7));//得到随机数
                for (int l = 0; l < 6; l++)
                {
                    if (b == ab[l])//判断每个抽取的数不同
                        goto AA;
                }
                ab[k] = b;
            }

你可能感兴趣的:(Random)