c# - List<T> get random element doesn't work -


i have following piece of code:

    private random r = new random();      private list<t> randomelement<t>(iqueryable<t> list, expression<func<t, bool>> e, int items = 3)     {         list = list.where(e);         return list.skip(r.next(list.count())).take(items).tolist();     }     

the problem when call , want example return 3 random items list, returns 3 2, 1 ?

i want @ time 3.

what doing wrong?

if have 10 elements in list, , ask 3 "random" items, in solution if random number generator returns 8, skip first 8 elements , has 2 items available return (items 9 , 10). why happening.

if want random items, instead shuffle list , not skip any, take number want.

randomize list<t>


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -