ok, lets see if i can explain this.
i have a List<Games> _Games = new List<Games>(); which containts 870 Games.
i have a Title ( each page will have a diffrent title, which is not related to the games, but the page will have the same game count ).
now, what i want to do, is order the games, based by the title i provide.
i actually tried to do something like this:
_Games = _Games.OrderByDescending(g => Math.Abs(Title.GetHashCode()));
but the order of the games stays the same.
Anyone has an idea how this kind of sorting can be created?
EDIT: you can see something similar to what i try to acheive here : Game/Quote of the day – how to?
but the accpeted answer there returns only 1 game, i want to return all the games.
EDIT: Sample title’s : “Hello World”, “Goodbye” === Diffrent Titles…
EDIT: this was conceptual.. added _Games = so you wont fixate on small things like that and avoiding my real question.
Your ordering attempt has two problems:
1.) You try to order by a fixed value (the hash code of the title) – ordering is internally done by most sort routines by comparing two items and positioning them accordingly. Now if you project each item to a fixed value they all are coming up as equal and no sort order can be established.
2.) You are not re-assigning the results of your ordering to your collection. You probably want something like
Edit:
Judging by your comments you just want to shuffle the list of games using a random sequence that will always be the same for a given title. If so, you can use a Fisher-Yates Shuffle combined with a Random instance that you pass the hash code of the title:
Then you can use it like this:
Keep in mind though that hash codes are not guaranteed to be stable, they can differ between platforms (.NET 32 vs 64 bit) and on each run time of your executable – it is only guaranteed that the same title will produce the same hash code within one execution of your program. If this is a problem for you, you might have to switch to your own method of determining a unique value for each title, i.e.: