I need to create a dictionary that has 2 keys per key, and it should be one of the 2 values with the same probability Must have to return.
Example:
myDicry {key = "A", value 1 = 15, value 2 = 56; } Int firstCall = myDicry ["A"]; // = 15 int second call = myDicry ["A"]; // = 56
I will actually apply it in a class that is a Dictionary & lt; TKey, TValue [] & gt;
Internally, you can also apply a variable number of values per key.
Like:
class RandomDictionary & lt; TKey, TValue & gt; {Dictionary & lt; Vaccines, TVs [] & gt; M_dict; Random m_random; Public RandomDictionary () {m_dict = New Dictionary & lt; TKey, TValue [] & gt; (); M_random = New Random (); } Public TV [key of this [vaccine] {{TValue [] values = M_dict [key]; Return value [m_random.Next (0, values.Length)]; }} Define Public Zero (the key of the vaccine, parameter TVV value [] value) {m_dict [key] = New TV [value. Length]; Array.Copy (value, m_dict [key], values.Length); } Public Child Trailgate Value (key of the vaccine, out TV value) {TValue [] value; If (M_dict.TryGetValue (key, out value)) {value = default (TValue); return false; } Value = value [m_random.Next (0, values.Length)]; Return true; }}
Comments
Post a Comment