c# - Get index of random matching value -


C # provides a way to get the first matching entry:

  int First = MyList.InxexOf (myList.Min ()) and  

Minimum ())

What is the easiest way to get a random index for a matching value such as:

  int anyOldOne = myList.RandomIndexOf (MyList You can get all the indexes and choose random index They are:    

  // Once it is only var rnd = New random (random); // Every time you want a random element, select Var key = myList.Min (); Var indices = mylist. ((N, index) => New {n, index}) Select (x = & gt; xn == key). Select (x = & gt; x.index) .toList (); int any oldone = index [rnd.Next (index.account)];   

Of course it would look better in a method.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -