random
Generates a decimal random value in the half-open range [0, 1).
Summary
Use this when random decimal values should stay in Arith form. Set CRYPTO: true only when the runtime provides crypto support.
AI Contract
Signature
Parameters
Returns
Returns a new Arith instance r where 0 <= r < 1.
Behavior
- Uses
decimalPlacesif provided, otherwise currentDECIMAL_PLACES. - Produced values have at most the requested number of decimal places.
- When
CRYPTOistrue, usesglobalThis.crypto.getRandomValuesor compatible random bytes support. - When
CRYPTOisfalse, usesMath.random.
Examples
Errors
- Throws if
decimalPlacesis invalid. - Throws if
CRYPTOistruebut no crypto source is available.
Agent Notes
- Do not assume deterministic output in tests; assert range and decimal-place constraints instead.
- Import from
@teakit/arith; preferimport { Arith } from "@teakit/arith". - Static helpers are called as
Arith.method(...)and do not require an instance receiver. - Do not generate
BigNumber,Decimal,isBigNumber, orisDecimalcompatibility APIs. - Use string inputs for exact decimal values when a static helper accepts numeric values.