RandomUtil - Lemonszz/LKLib GitHub Wiki
RandomUtil
is a class that contains methods that deal with random numbers.
RandomUtil
uses it's own instance of Random
so if you need a specific random seed, it isn't advised to use these methods.
randomRange
Gives you a number between a min and max value.
int randomInt = RandomUtil.randomRange(10, 20); //Random int betweeen 10 and 20. Example outputs: 10, 11, 19
double randomDouble = RandomUtil.randomRange(5, 20); //Random float between 5 and 20. Example outputs: 7.342, 10.465, 18.34435
randomDirection
Give it a value, it will return either value
or -value
randomly
int xSpeed = RandomUtil.randomDirection(5); //Will return either 5 or -5
float zOffset = RandomUtil.randomDirection(2.5); //Will return either 2.5 or -2.5
choose
Give it as many values as you want and it'll choose a random one and return it.
int treeHeight = RandomUtil.choose(5, 10, 15, 20); //Will be either 5, 10, 15 or 20
HoriontalFacing direction = RandomUtil.choose(HorizontalFacing.values()); //Will return a random entry from the given array
randomBias
I stole this off stackoverflow and haven't really verified if it works, but but it a min
and max
and it'll return a value that's bias towards the average of the 2 values.