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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -