Given a range of Bytes, chooses one of them randomly.
Given a range of Bytes, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Chars, chooses one of them randomly.
Given a range of Chars, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Doubles, chooses one of them randomly.
Given a range of Doubles, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of finite Doubles, chooses one of them randomly.
Given a range of finite Doubles, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of finite Floats, chooses one of them randomly.
Given a range of finite Floats, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Floats, chooses one of them randomly.
Given a range of Floats, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Ints, chooses one of them randomly.
Given a range of Ints, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Longs, chooses one of them randomly.
Given a range of Longs, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Doubles, chooses one of them randomly.
Given a range of negative Doubles, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative, finite Doubles, chooses one of them randomly.
Given a range of negative, finite Doubles, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative, finite Floats, chooses one of them randomly.
Given a range of negative, finite Floats, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Floats, chooses one of them randomly.
Given a range of negative Floats, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Ints, chooses one of them randomly.
Given a range of negative Ints, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Longs, chooses one of them randomly.
Given a range of negative Longs, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Doubles (maybe including zero), chooses one of them randomly.
Given a range of negative Doubles (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative, finite Doubles (maybe including zero), chooses one of them randomly.
Given a range of negative, finite Doubles (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative, finite Floats (maybe including zero), chooses one of them randomly.
Given a range of negative, finite Floats (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Floats (maybe including zero), chooses one of them randomly.
Given a range of negative Floats (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Ints (maybe including zero), chooses one of them randomly.
Given a range of negative Ints (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of negative Longs (maybe including zero), chooses one of them randomly.
Given a range of negative Longs (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Doubles (excluding zero), chooses one of them randomly.
Given a range of Doubles (excluding zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
In order to avoid returning 0, this function is very slightly biased towards returning 1 instead.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of finite Doubles (excluding zero), chooses one of them randomly.
Given a range of finite Doubles (excluding zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
In order to avoid returning 0, this function is very slightly biased towards returning 1 instead.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of finite Floats (excluding zero), chooses one of them randomly.
Given a range of finite Floats (excluding zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
In order to avoid returning 0, this function is very slightly biased towards returning 1 instead.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Floats (excluding zero), chooses one of them randomly.
Given a range of Floats (excluding zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
In order to avoid returning 0, this function is very slightly biased towards returning 1 instead.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Ints (excluding zero), chooses one of them randomly.
Given a range of Ints (excluding zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
In order to avoid returning 0, this function is very slightly biased towards returning 1 instead.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Longs (excluding zero), chooses one of them randomly.
Given a range of Longs (excluding zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
In order to avoid returning 0, this function is very slightly biased towards returning 1 instead.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Doubles, chooses one of them randomly.
Given a range of positive Doubles, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive finite Doubles, chooses one of them randomly.
Given a range of positive finite Doubles, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive, finite Floats, chooses one of them randomly.
Given a range of positive, finite Floats, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Floats, chooses one of them randomly.
Given a range of positive Floats, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Ints, chooses one of them randomly.
Given a range of positive Ints, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Longs, chooses one of them randomly.
Given a range of positive Longs, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Doubles (maybe including zero), chooses one of them randomly.
Given a range of positive Doubles (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive, finite Doubles (maybe including zero), chooses one of them randomly.
Given a range of positive, finite Doubles (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive, finite Floats (maybe including zero), chooses one of them randomly.
Given a range of positive, finite Floats (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Floats (maybe including zero), chooses one of them randomly.
Given a range of positive Floats (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Ints (maybe including zero), chooses one of them randomly.
Given a range of positive Ints (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of positive Longs (maybe including zero), chooses one of them randomly.
Given a range of positive Longs (maybe including zero), chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given a range of Shorts, chooses one of them randomly.
Given a range of Shorts, chooses one of them randomly.
Note that, while the from parameter is usually smaller than to, that is not required; the function will cope appropriately if they are in reverse order.
The choice is inclusive: either the from or to values may be returned.
One end of the range to select from.
The other end of the range.
A value from that range, inclusive of the ends.
Given the endpoints of a finite-Float range, and a scaling factor, this computes the number that far across the range.
Given the endpoints of a finite-Float range, and a scaling factor, this computes the number that far across the range.
This deals with edge cases that can result in infinities in the math.
A scaling factor between 0 and 1.
The lower end of the range.
The upper end of the range.
The Float that is the scaling factor distance across that range.
Get a certain number of random bits.
Get a certain number of random bits.
You don't usually call this directly. Instead, call more-specific functions such as nextInt, which calls this for the correct number of bits and then casts that to the desired type.
The number of random bits you need.
The random bits, and the next Randomizer to user.
Get a 1 or a 0.
Get a 1 or a 0.
a 1 or 0 as an Int.
Get a random 8-bit Byte.
Get a random 8-bit Byte.
A random Byte, and the next Randomizer to use.
Get a random 16-bit Char.
Get a random 16-bit Char.
Note: this intentionally avoids invalid Unicode chars between 0xD800 and 0xDFFF; when one of those is generated, this instead returns a Char between 0x0000 and 0x00FF. So this function slightly favors that first code block. (Which is the most common one in practice, anyway.)
A random Char, and the next Randomizer to use.
Get a random Double.
Get a random Double.
This will randomize the sign, exponent and mantissa, so it can return any possible Double.
A random Double, and the next Randomizer to use.
Get a random Double between 0 and 1.
Get a random Double between 0 and 1.
When working with Double, you often want a value between 0 and 1 -- this sort of proportion is a common use case for Double. This function makes it easy to grab one.
A random Double in that range, and the next Randomizer to use.
Get a random non-infinite Double.
Get a random non-infinite Double.
This can return either a positive or negative value, or zero, but guards against returning either Double.PositiveInfinity, Double.NegativeInfinity, or Double.NaN.
A random finite Double, and the next Randomizer to use.
Get a random non-infinite Float.
Get a random non-infinite Float.
This can return either a positive or negative value, or zero, but guards against returning either Float.PositiveInfinity, Float.NegativeInfinity, or Float.NaN.
A random finite Float, and the next Randomizer to use.
Get a random Float.
Get a random Float.
This will randomize the sign, exponent and mantissa, so it can return any possible Float.
A random Float, and the next Randomizer to use.
Get a random Float between 0 and 1.
Get a random Float between 0 and 1.
When working with Floats, you often want a value between 0 and 1 -- this sort of proportion is one of the more common use cases for Floats. This function makes it easy to grab one.
A random Float in that range, and the next Randomizer to use.
Get a random 32-bit Int.
Get a random 32-bit Int.
A random Int, and the next Randomizer to use.
Get a random list of elements of type T.
Get a random list of elements of type T.
This function requires an implicit parameter that says how to generate values of T, as well as the number of them to generate. (Which may be zero.)
The type to generate.
How many values to generate for the List.
A Generator, that provides values of type T.
A List of values of the desired type.
Get a random 64-bit Long.
Get a random 64-bit Long.
A random Long, and the next Randomizer to use.
Get a random Double less than zero.
Get a random Double less than zero.
Note: it is possible (although rare) for this to return Double.NegativeInfinity. If you want to avoid that, use nextNegFiniteDouble instead.
A random negative Double, and the next Randomizer to use.
Get a random Double less than zero.
Get a random Double less than zero.
This guards against returning Double.NegativeInfinity, so you can have confidence that the returned number is real and finite.
A random negative Double, and the next Randomizer to use.
Get a random Float less than zero.
Get a random Float less than zero.
This guards against returning Float.NegativeInfinity, so you can have confidence that the returned number is real and finite.
A random negative Float, and the next Randomizer to use.
Get a random Float less than zero.
Get a random Float less than zero.
Note: it is possible (although rare) for this to return Float.NegativeInfinity. If you want to avoid that, use nextNegFiniteFloat instead.
A random negative Float, and the next Randomizer to use.
Get a random Int less than zero.
Get a random Int less than zero.
A random negative Int, and the next Randomizer to use.
Get a random Long less than zero.
Get a random Long less than zero.
A random negative Long, and the next Randomizer to use.
Get a random Double less than or equal to zero.
Get a random Double less than or equal to zero.
Note: it is possible (although rare) for this to return Double.NegativeInfinity. If you want to avoid that, use nextNegZFiniteDouble instead.
A random negative-or-zero Double, and the next Randomizer to use.
Get a random Double less than or equal to zero.
Get a random Double less than or equal to zero.
This guards against Double.NegativeInfinity, so it will always return a non-infinite value.
A random negative-or-zero Double, and the next Randomizer to use.
Get a random Float less than or equal to zero.
Get a random Float less than or equal to zero.
This guards against Float.NegativeInfinity, so it will always return a non-infinite value.
A random negative-or-zero Float, and the next Randomizer to use.
Get a random Float less than or equal to zero.
Get a random Float less than or equal to zero.
Note: it is possible (although rare) for this to return Float.NegativeInfinity. If you want to avoid that, use nextNegZFiniteFloat instead.
A random negative-or-zero Float, and the next Randomizer to use.
Get a random Int less than or equal to zero.
Get a random Int less than or equal to zero.
A random negative-or-zero Int, and the next Randomizer to use.
Get a random Long less than or equal to zero.
Get a random Long less than or equal to zero.
A random negative-or-zero Long, and the next Randomizer to use.
Get a random non-zero Double.
Get a random non-zero Double.
This can return any Double except zero.
Note that this can return infinite values; if you want to avoid that, use nextNonZeroFiniteDouble instead.
A random non-zero Double, and the next Randomizer to use.
Get a random non-zero Double.
Get a random non-zero Double.
This can return any Double except zero, Double.PositiveInfinity, or Double.NegativeInfinity.
A random non-zero Double, and the next Randomizer to use.
Get a random non-zero Float.
Get a random non-zero Float.
This can return any Float except zero, Float.PositiveInfinity, or Float.NegativeInfinity.
A random non-zero Float, and the next Randomizer to use.
Get a random non-zero Float.
Get a random non-zero Float.
This can return any Float except zero.
Note that this can return infinite values; if you want to avoid that, use nextNonZeroFiniteFloat instead.
A random non-zero Float, and the next Randomizer to use.
Get a random non-zero Int.
Get a random non-zero Int.
This can return any Int except zero.
A random non-zero Int, and the next Randomizer to use.
Get a random non-zero Long.
Get a random non-zero Long.
This can return any Long except zero.
A random non-zero Long, and the next Randomizer to use.
Get a random Double greater than zero.
Get a random Double greater than zero.
Note: it is possible (although rare) for this to return Double.PositiveInfinity. If you want to avoid that, use nextPosFiniteDouble instead.
A random positive Double, and the next Randomizer to use.
Get a random Double greater than zero.
Get a random Double greater than zero.
This guards against returning Double.PositiveInfinity, so you can have confidence that the returned number is real and finite.
A random positive Double, and the next Randomizer to use.
Get a random, finite Float greater than zero.
Get a random, finite Float greater than zero.
This methods guards against returning Float.PositiveInfinity -- you will always receive a real value.
A random positive Float, and the next Randomizer to use.
Get a random Float greater than zero.
Get a random Float greater than zero.
Note: it is possible (although rare) for this to return Float.PositiveInfinity. If you want to avoid that, use nextPosFiniteFloat instead.
A random positive Float, and the next Randomizer to use.
Get a random Integer greater than zero.
Get a random Integer greater than zero.
Note: if the underlying algorithm tries to generate 0, this generates 1, so it is very slightly biased towards returning 1.
A random positive Integer, and the next Randomizer to use.
Get a random Long greater than zero.
Get a random Long greater than zero.
A random positive Long, and the next Randomizer to use.
Get a random Double greater than or equal to zero.
Get a random Double greater than or equal to zero.
Note: it is possible (although rare) for this to return Double.NegativeInfinity. If you want to avoid that, use nextPosZFiniteDouble instead.
A random positive Double, and the next Randomizer to use.
Get a random Double greater than or equal to zero.
Get a random Double greater than or equal to zero.
This guards against returning Double.NegativeInfinity.
A random negative Double, and the next Randomizer to use.
Get a random Float greater than or equal to zero.
Get a random Float greater than or equal to zero.
This guards against returning Float.PositiveInfinity.
A random positive Float, and the next Randomizer to use.
Get a random Float greater than or equal to zero.
Get a random Float greater than or equal to zero.
Note: it is possible (although rare) for this to return Float.PositiveInfinity. If you want to avoid that, use nextPosZFiniteFloat instead.
A random positive Float, and the next Randomizer to use.
Get a random Integer greater than or equal to zero.
Get a random Integer greater than or equal to zero.
A random positive Integer (or zero), and the next Randomizer to use.
Get a random Long greater than or equal to zero.
Get a random Long greater than or equal to zero.
A random positive Long (or zero), and the next Randomizer to use.
Computes the next Randomizer to use.
Computes the next Randomizer to use.
Since Randomizer is immutable (and would thus return the same value over and over), you don't usually use the same instance more than once. Instead, you should fetch the next one, and use that for the next operation.
You usually don't need to call this directly; instead, the next Randomizer is returned from each operation, along with the random value.
The next Randomizer, ready to use.
Get a random 16-bit Short.
Get a random 16-bit Short.
A random Short, and the next Randomizer to use.
Get a random String.
Get a random String.
This takes a desired length, and generates a String of that length. Do not expect this String to make any sense -- it is literally just a string of random Unicode characters, and will typically contain little or no conventional ASCII.
The number of characters to include in the String.
A highly-random String of the specified length, and the next Randomizer to use.
Provide random values, of many different types.
This is loosely inspired by java.util.Random (and is designed to produce the same values in conventional cases), with two major differences:
On the first of those points, this returns many data types, including many of the tightly-defined numeric types from Scalactic. These allow you to put tight constraints on precisely what numbers you want to have available -- positive, negative, zeroes, infinities and so on. We strongly recommend that you use the function that most exactly describes the values you are looking for.
That second point is the more important one. You shouldn't call the same Randomizer over and over, the way you would do in Java. Instead, each call to a Randomizer function returns the next Randomizer, which you should use for the next call.
If you are using random floating-point values: the algorithms in use here produce random values across the potential space of values. But due to the way floating-point works, this means that these values are strongly biased towards small numbers. There are many floating-point numbers with negative exponents, so you may get more numbers in the range between -1 and 1 than you expect.