Skip to content

Instantly share code, notes, and snippets.

@cubed2d
Created January 30, 2015 10:04
Show Gist options
  • Save cubed2d/7b574b991e82c039dce1 to your computer and use it in GitHub Desktop.
Save cubed2d/7b574b991e82c039dce1 to your computer and use it in GitHub Desktop.
public Random random; <- put this in one of your class files (Usually Xna has a Game class? probably that one
random = new Random(); <-- In the same file put this somewhere. Xna games tend to have a LoadContent or a Initialize method? that would be a good place. This creates and instance of the Random class. Random is an object that has lots of methods for giving you differnt types of random numbers, like the name suggests! :)
var item = myList[random.Next(myList.count)]; <- WHen you want to get the random item. the Next method on Random makes it generate the next random number. Passing in the length/count of the items in your list makes it generate a number thats between 0 and that number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment