### common method of Sprite random generation in games

The following code was written in Java when I was working on my graduation design game. Math.random() was used to select the key parts.

Int [] nums =,1,2,3 {0}; /* math.random () takes a 0-1 float, *floor is rounded down, *index is the table below the array, */ int index = (int) math.floor (nums.length* math.random ()); // Random number group subscript int type = nums[index]; Else if(type == 1){// Perform method 2} else if(type == 2){// perform method 3} else if(type == 3){ // Execute method 4}Copy the code