C# random value from dictionary and tuple -
i have following code, , need random item contains string "region_1" dictionary.
public static dictionary<int, tuple<string, int, currencytype>> itemarray = new dictionary<int, tuple<string, int, currencytype>>() { { 0xb3e, new tuple<string, int, currencytype>("region_1", 1500, currencytype.fame) } }; public static int generateitemid(string shopid) { var generateditem = itemarray.elementat(new random().next(0, itemarray.count)).key; }
how select this?
it's not possible efficiently...
first create static random
@ class level... prevent non-random behaviour if run query on short period of time... (it's seeded discrete clock)
static random rnd = new random();
then:
var item = itemarray.values .where(t => t.item1 == shopid) .orderby(_ => rnd.next()) .firstordefault()
Comments
Post a Comment