RandomExtensionsNextHalf(Random, Half, FloatScale) Method

Returns a non-negative random Half value that is less than or equal to the specified maxValue.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static Half NextHalf(
	this Random random,
	Half maxValue,
	FloatScale scale = FloatScale.Auto
)

Parameters

random  Random
The Random instance to use.
maxValue  Half
The upper bound of the random number returned.
scale  FloatScale  (Optional)
The scale to use to generate the random number. This parameter is optional.
Default value: Auto.

Return Value

Half
A half-precision floating point number that is greater than or equal to 0.0 and less than or equal to maxValue.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Random. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

In most cases return value is less than maxValue. Return value can be equal to maxValue in very edge cases, such as using very small ranges close to the limits of Half.

If scale is Auto, then always the ForceLinear option is used.

Generating random numbers by this method on the logarithmic scale is about 3 times slower than on the linear scale.

Exceptions

ArgumentNullExceptionrandom is .
ArgumentOutOfRangeExceptionmaxValue is less than 0.0
-or-.
scale is not a valid value of FloatScale.

See Also