c# - Linq order by random without GUID -
need order random using linq , can't use guid.newguid(), need this: .orderby(x => "somestring").
a mobile app suppose generate random string , call webapi , because maintained paging mobile app sends same random string different page number every time sends random string ordering should same different skip ... .
how possible? if not string maybe number or fixed every linq query.
edit:
this webapi
[route("getchannels/{id}/{word}/{page}/{randomstring}")] public ienumerable<channels> getchannels(int id, string word, int page, string randomstring) { ... if (canpage) { var channels = db.channels.where(x => (id == 0) || (x.categoryid == id)) .where(q => word == "0" || (q.title.contains(word) || q.desc.contains(word))) .orderby(x => randomstring).skip(skip).take(pagesize).tolist(); } ...
if want return results in random order, order same if sending same string client, can use random
class pseudo-random order. random generator can accept seed - value, used calculate starting value of pseudo-random sequence. passing string
can use it's hash code integer value seed:
var seed = randomstring.gethashcode(); var random = new random(seed); var channels = db.channels .where(x => (id == 0) || (x.categoryid == id)) .where(q => word == "0" || (q.title.contains(word) || q.desc.contains(word))) .asenumerable() // randomizing should happen on client side .orderby(x => random.next()) .skip(skip) .take(pagesize) .tolist();
Comments
Post a Comment