Created
January 30, 2015 10:04
-
-
Save cubed2d/7b574b991e82c039dce1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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