Package com.deco2800.game.utils.random
Class PseudoRandom
java.lang.Object
com.deco2800.game.utils.random.PseudoRandom
This class provides an API for seeding Pseduo-Generated Random features.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
getRandomItem
(List<T> items) This method selects an item from a list by pseudo-randomly generating an integer between 0 and the length of the list, and returning the element at this index.static double
This method generates a pseudo-randomly generated number between 0 and 1.static double
seedRandomDouble
(double lowerBound, double upperBound) This method generates pseudo-randomly generated floating point number between the specified lower-bound and upper-bound.static int
seedRandomInt
(int lowerBound, int upperBound) This method generates pseudo-randomly generated integers between the specified lowerBound and upperBound.
-
Constructor Details
-
PseudoRandom
public PseudoRandom()
-
-
Method Details
-
randomUnitNumberGenerator
public static double randomUnitNumberGenerator()This method generates a pseudo-randomly generated number between 0 and 1.- Returns:
- double between 0 and 1.
-
seedRandomDouble
public static double seedRandomDouble(double lowerBound, double upperBound) This method generates pseudo-randomly generated floating point number between the specified lower-bound and upper-bound.- Parameters:
lowerBound
- : Floating point lower bound.upperBound
- : Floating point upper bound.- Returns:
- double between lowerBound and upperBound.
-
seedRandomInt
public static int seedRandomInt(int lowerBound, int upperBound) This method generates pseudo-randomly generated integers between the specified lowerBound and upperBound. NOTE: lowerBound must be less than upperBound.- Parameters:
lowerBound
- : Integer lower bound.upperBound
- : Integer upper bound.- Returns:
- Integer value between lowerBound and upperBound.
-
getRandomItem
This method selects an item from a list by pseudo-randomly generating an integer between 0 and the length of the list, and returning the element at this index.- Type Parameters:
T
- Can be any Class.- Parameters:
items
- A list of items.- Returns:
- An item chosen pseudo-randomly from items
-