数组里的数据如何提出来

有一个数组:
string[] chars = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","a", "b", "c", "d", "e", "f", "g", "h", "i"
,"j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A", "B", "C", "D", "E", "F", "G", "H", "I"
,"J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","~","!","@","#","$","%","^","&","*","(",")","_","+"
,"=","-","`","<",">","?",",",".","/"};

现在我想得到10-16位的字符串,这些串从上面的数组中任意字符组合得到,请问高手,怎么写代码呢?
运行成功,再送100分!以先解决且效率高的答案为准,谢谢啦
不是随机数呀
比如:
第一个串为:0123456789
第二个串为:012345678a
.........
第N个串为:9abc856d145fa*faf*
.........

第1个回答  2007-11-22
终于搞定了...不知道效率怎么样?试试吧...
...read()数字最大不能超过int32....不过一般用不着那么大的吧...先这样吧..有问题再PM我..
程序没有说明,应该可以看懂吧..

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'
,'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'
,'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ','~','!','@','#','$','%','^','&','*','(',')','_','+'
,'=','-','`','<','>','?',',','.','/'};
int num = int.Parse(Console.ReadLine());
SortedList<int, int> slFirst = new SortedList<int, int>();
for (int i = 0; i < 10; i++)
{
slFirst.Add(i, i);
}
StringBuilder sbChar = new StringBuilder();
StringBuilder sbInt = new StringBuilder();
SortedList<int, int> sl = new SortedList<int, int>();
SortedList<int, char> newSl = new SortedList<int, char>();
int slKey = 0;
int numCount = num;
while (numCount > 0)
{

sl.Add(slKey, numCount % chars.Length);
numCount /= chars.Length;
++slKey;
}
while (sl.Count < slFirst.Count)
{
for (int i = sl.Count; i < slFirst.Count; i++)
{
sl.Add(i+1, 0);
}
}
int intTemp;
// bool isCarry = false;
int intCarry = 0;
string result="";
for (int i = 0; i < sl.Count; i++)
{
intTemp = sl.Values[sl.Count-1-i] + slFirst.Keys[i];
if (intTemp < chars.Length)
{
// isCarry = false;
intCarry = 0;
}
else
{
intTemp -= chars.Length;
// isCarry = true;
intCarry = 1;
}

newSl.Add(i,chars[intTemp +intCarry]);
result += newSl[i];

}
Console.WriteLine("the {0}th string is {1}",num,result);
Console.Read();
}
}

参考资料:还有什么问题,就PM我吧..

第2个回答  2007-11-22
随机数r,chars[r]

不是随机数?
那就得到n,chars[n]
第3个回答  2007-11-22
10位
Random rnd = new Random();
string str="";
for(int i=0;i<10;i++)
{
str += chars[rnd.Next(chars.Length).ToString()];
}本回答被提问者采纳
第4个回答  2007-11-22
不是说随机数?