首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#新手请问一个关于生成随机数的有关问题

2012-02-14 
C#新手请教一个关于生成随机数的问题请教一个关于随机数的问题,比如Random ra new Random()int a ra.

C#新手请教一个关于生成随机数的问题

请教一个关于随机数的问题,比如
 Random ra = new Random();
  int a = ra.Next(0, 10);
现在想Radom一个rb,范围是0到10但是除去ra,请问一下该如何实现..
类似的,rc,范围也是0到10,但是除去ra和rb,该如何实现..

[解决办法]

C# code
using System;using System.Collections.Generic;public class TestList{    public static void Main()    {            List<int> aa = new List<int>();            for (int i = 0; i <10; i++)            {                aa.Add(i);// 0,1, 2, 3, 4, 5, 6, 7, 8, 9;            }            List<int> bb = new List<int>();            Test(aa, bb);            foreach(int i in bb)        {            Console.WriteLine(i);        }            Console.ReadLine();    }        public static void Test(List<int> aa, List<int> bb)        {            if (aa.Count == 0) return;            Random ra = new Random();            int a = ra.Next(aa.Count);            bb.Add(aa[a]);            for (int i = 0; i < aa.Count; i++)            {                if (aa[i] == aa[a])                {                    aa.RemoveAt(i);                }            }            Test(aa, bb);        }}; 

热点排行