当时没做出来,现在想了想,这样能写出来,不知道其它大虾还有更好的方法不?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace RandomTest
{
class Program
{
static void Main(string[] args)
{
List<string> aRandomList=new List<string>(); for (int i = 0; i < 100; )
{
string stemp = GetRandom();
if (aRandomList.Contains(stemp))
continue;
else
{
aRandomList.Add(stemp);
i++;
}
}
Console.Read();
}
static string GetRandom()
{
string words = "abcdefghijklmnopqrstuvwxyz0123456789";
StringBuilder oSB = new StringBuilder();
Random r = new Random(); for (int i = 0; i < 8; i++)
{
string word = words.Substring(r.Next(words.Length - 1), 1);
oSB.Append(word);
}
string sTemp = oSB.ToString();
return sTemp;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace RandomTest
{
class Program
{
static void Main(string[] args)
{
List<string> aRandomList=new List<string>(); for (int i = 0; i < 100; )
{
string stemp = GetRandom();
if (aRandomList.Contains(stemp))
continue;
else
{
aRandomList.Add(stemp);
i++;
}
}
Console.Read();
}
static string GetRandom()
{
string words = "abcdefghijklmnopqrstuvwxyz0123456789";
StringBuilder oSB = new StringBuilder();
Random r = new Random(); for (int i = 0; i < 8; i++)
{
string word = words.Substring(r.Next(words.Length - 1), 1);
oSB.Append(word);
}
string sTemp = oSB.ToString();
return sTemp;
}
}
}
{
int _s = 0;
string _str = "abcdefghijklmnopqrstuvwxyz0123456789";
for (int i = 0; i < _str.Length; i++)
{
for (int _i = 0; _i < _str.Length; _i++)
{
if (_str.Length - _i >= 7)
{
Response.Write(_str[i] + _str.Substring(_i, 7) + "<br/>");
_s += 1;
}
else
{
break;
}
}
}
Response.Write("一共" + _s + "个元素");
}
Random rand = new Random(Guid.NewGuid().GetHashCode());
for(int i=;i<arr.Length;i++)
{
result+=arr[rand.Next(0,arr.Length)];
}
char[] arr="12..".ToCharArray();
Random rand = new Random(Guid.NewGuid().GetHashCode());
for(int i=;i<arr.Length;i++)
{
result+=arr[rand.Next(0,arr.Length)];
}
{
for (int i = 0; i < 1000000; i++)
{
Guid g = Guid.NewGuid();
string result = g.ToString().Substring(0, 8);
Console.WriteLine(result);
}
}[/align]
{
for (int i = 0; i < 1000000; i++)
{
Guid g = Guid.NewGuid();
string result = g.ToString().Substring(0, 8);
Console.WriteLine(result);
}
}
Random rand = new Random(System.DateTime.Now.Ticks);//注意保证这个数字的唯一性
for(int i=;i<arr.Length;i++)
{
result+=arr[rand.Next(0,arr.Length)];
}
81e047fb-2d8e-4a60-9317-a325203797a8 这是其中一组
前8……个不就是这个意思了?
for (int i = 0; i < 100; i++)
{
result.Add( System.Guid.NewGuid().ToString().Substring(0, 8)) ;
}
static void Main(string[] args)
{
int NUM = 100; List<string> list = new List<string>();
string s;
while(list.Count<100)
{
s = Guid.NewGuid().ToString().Substring(0, 8);
if (ss.Contains(s))
continue;
list.Add(s);
}
}
private void a()
{
char[] arr = "1234567890abcdefghijklmnopqrstuvwxyz".ToCharArray();
Random rand = new Random();
Dictionary<string,string> strs = new Dictionary<string,string>(); int i = 0;
while (i<100)
{
bool flag2 = true;
string temp = "";
for(int j = 0;j<8;j++)
{
temp += arr[rand.Next(0, arr.Length)];
}
if(!strs.ContainsKey(temp))
{
strs.Add(temp,"");
i++;
}
} foreach(KeyValuePair<string,string> item in strs)
{
Response.Write(item.Key);
Response.Write("<br/>");
}
}
System.IO.Path.GetTempFileName()
static void Main(string[] args)
{
for (int i = 10000000; i < 10000100; ++i)
{
Console.Write("{0}\n", i.ToString());
}
Console.ReadKey();
}