c# - What data structure can I use to access its contents randomly? -
i need add bunch of items data structure , later access of items within in random order. how can this?
to more specific, adding urls list<string>
object. added in way such adjacent urls on same server. when access list using parallel.foreach statement, returns items in order added them. okay, when making web requests in parallel, tends overwhelm servers , leads timeouts. data structure can use return items in more random way when run parallel.foreach statement on object (i.e., not in order added them)?
public static void shuffle<t>(this ilist<t> list) { random rng = new random(); int n = list.count; while (n > 1) { n--; int k = rng.next(n + 1); t value = list[k]; list[k] = list[n]; list[n] = value; } } list<product> products = getproducts(); products.shuffle();
Comments
Post a Comment