0

I am building a game with asp, sql, c#, and XML. I have an xml document that holds all the characters and their numbers (which is used to display their pictures).

I am pulling the information and displaying it using a DataList. Currently it pulls and displays all the characters in my xml. I desire for it only to pull a certain amount of characters (generated randomly) and display those for the duration of the game. Then the next game a different set of characters will be randomly chosen and played with.

Not sure if it's important to note. The game is a two player turn based game. The set of characters displayed needs to be the same for both players.

user692942
  • 16,398
  • 7
  • 76
  • 175
Regis
  • 166
  • 4
  • 17
  • It sounds like you want to choose a random subset of elements from a larger collection. See [this related question](http://stackoverflow.com/q/48087/1127114) for possible approaches. – Michael Liu Nov 23 '14 at 22:26
  • You have a list of N items, and you want a random selection of K of them. You can use a [Fisher–Yates shuffle](http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) to shuffle the list, then take the first K items. This guarantees no duplicates. – dbc Nov 23 '14 at 23:00

1 Answers1

0

Picking x random items from a set list is something you can do with a shuffle bag.

Carra
  • 17,808
  • 7
  • 62
  • 75