Random r = new Random(); int i = r.Next(1, objHash.Keys.Count); int k = 0; foreach (string skey in objHash.Keys) { if (i == k) return objHash[skey]; else k++; }
static void RndHashTable() { Hashtable ht = new Hashtable(); ht.Add("a", "1"); ht.Add("b", "2"); ht.Add("i", "3"); ArrayList listValues = new ArrayList(ht.Values); ArrayList listKeys = new ArrayList(ht.Keys); foreach (var s in listKeys) { listValues.Add(s); } Random rndValue = new Random(); int i = 0; int j; while (i <listValues.Count) { j=rndValue.Next(0,listValues.Count); Console.WriteLine(listValues[j]); i++; } }
int i = r.Next(1, objHash.Keys.Count);
int k = 0; foreach (string skey in objHash.Keys)
{
if (i == k) return objHash[skey];
else k++;
}
{
Hashtable ht = new Hashtable();
ht.Add("a", "1");
ht.Add("b", "2");
ht.Add("i", "3");
ArrayList listValues = new ArrayList(ht.Values);
ArrayList listKeys = new ArrayList(ht.Keys);
foreach (var s in listKeys)
{
listValues.Add(s);
} Random rndValue = new Random();
int i = 0;
int j;
while (i <listValues.Count)
{
j=rndValue.Next(0,listValues.Count);
Console.WriteLine(listValues[j]);
i++;
}
}