Click here to Skip to main content
15,900,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: Char problem [modified] Pin
CodeItWell5-Jan-07 10:29
CodeItWell5-Jan-07 10:29 
GeneralRe: Char problem Pin
Ravi Bhavnani5-Jan-07 11:18
professionalRavi Bhavnani5-Jan-07 11:18 
QuestionC#.NET Email Pin
TRK@UK5-Jan-07 6:26
TRK@UK5-Jan-07 6:26 
AnswerRe: C#.NET Email Pin
Ravi Bhavnani5-Jan-07 6:36
professionalRavi Bhavnani5-Jan-07 6:36 
AnswerRe: C#.NET Email Pin
Guffa5-Jan-07 8:03
Guffa5-Jan-07 8:03 
GeneralRe: C#.NET Email Pin
Dan Neely5-Jan-07 8:26
Dan Neely5-Jan-07 8:26 
GeneralRe: C#.NET Email Pin
Guffa6-Jan-07 10:09
Guffa6-Jan-07 10:09 
QuestionGetting a random entry from a Generic Dictionary [modified] Pin
Mike Heffernan5-Jan-07 5:58
Mike Heffernan5-Jan-07 5:58 
Greetings all. I'm writing a performance test harness for a system that uses the System.Collections.Generics.Dictionary to contain some rather large collections of things, and I'd like to pick a random entry from these dictionaries and do something with it. The key and values cannot be easily produced randomly, so my best bet is to randomize an int between 0 and dict.Count, and then pull the entry. Obviously this would work fine with a Hashtable, since it has an integer indexer.

But I can't find any way to kludge an int indexer into a Dictionary that isn't a performance pig (which kind of distorts my performance test results). For example, my current (Uggh) code does this:

dictKeyType[] dictKeys = new dictKeyType[dict.Count];<br />
dict.Keys.CopyTo(dictKeys, 0);<br />
<br />
int idx = GetRandomInt(dictKeys.Length - 1);<br />
dictKeyType randomKey = dictKeys[idx];<br />


but obviously for large amounts of data, the array copy is going to distort both time and memory use. The distortion in memory use can be avoided by doing a foreach loop through the keys while decrementing the randomInt and then taking the value when you hit zero... but man, wouldn't it be better to just have an int indexer on the Dictionary (or Keys)?

Anyone have an idea on this? Or have I just missed something immensely simple? Smile | :)


Mike
---------------------
www.opusedge.com

AnswerRe: Getting a random entry from a Generic Dictionary Pin
Ravi Bhavnani5-Jan-07 6:41
professionalRavi Bhavnani5-Jan-07 6:41 
GeneralRe: Getting a random entry from a Generic Dictionary Pin
Mike Heffernan5-Jan-07 9:03
Mike Heffernan5-Jan-07 9:03 
GeneralRe: Getting a random entry from a Generic Dictionary Pin
Ravi Bhavnani5-Jan-07 9:28
professionalRavi Bhavnani5-Jan-07 9:28 
AnswerRe: Getting a random entry from a Generic Dictionary Pin
Luc Pattyn5-Jan-07 7:22
sitebuilderLuc Pattyn5-Jan-07 7:22 
GeneralRe: Getting a random entry from a Generic Dictionary Pin
Mike Heffernan5-Jan-07 9:05
Mike Heffernan5-Jan-07 9:05 
QuestionHow to insert picture in RTB & hot to printing from Rich Text Box Pin
TrooperIronMan5-Jan-07 5:42
TrooperIronMan5-Jan-07 5:42 
AnswerRe: How to insert picture in RTB & hot to printing from Rich Text Box Pin
TrooperIronMan6-Jan-07 7:44
TrooperIronMan6-Jan-07 7:44 
GeneralRe: How to insert picture in RTB & hot to printing from Rich Text Box Pin
TrooperIronMan6-Jan-07 11:19
TrooperIronMan6-Jan-07 11:19 
QuestionConnect to running instance of C# application Pin
softplanner5-Jan-07 5:35
softplanner5-Jan-07 5:35 
AnswerRe: Connect to running instance of C# application Pin
Not Active5-Jan-07 6:03
mentorNot Active5-Jan-07 6:03 
QuestionWindows service to open folder Pin
milan5-Jan-07 5:29
milan5-Jan-07 5:29 
QuestionMDI Forms Pin
Civic065-Jan-07 4:44
Civic065-Jan-07 4:44 
AnswerRe: MDI Forms Pin
Ravi Bhavnani5-Jan-07 4:59
professionalRavi Bhavnani5-Jan-07 4:59 
QuestionC# Threading Pin
manustone5-Jan-07 4:44
manustone5-Jan-07 4:44 
AnswerRe: C# Threading Pin
Ravi Bhavnani5-Jan-07 4:57
professionalRavi Bhavnani5-Jan-07 4:57 
GeneralRe: C# Threading Pin
manustone5-Jan-07 11:00
manustone5-Jan-07 11:00 
QuestionEnumerate over an enumeration Pin
eggsovereasy5-Jan-07 4:29
eggsovereasy5-Jan-07 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.