From 3cbc62ee43737e3afae0dd2e6597ff703689634e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 15 Sep 2024 17:00:25 -0400 Subject: Add docs on bytes --- docs/bytes.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 docs/bytes.md (limited to 'docs/bytes.md') diff --git a/docs/bytes.md b/docs/bytes.md new file mode 100644 index 00000000..36180428 --- /dev/null +++ b/docs/bytes.md @@ -0,0 +1,35 @@ +# Byte Values + +Byte values have the type `Byte`, which corresponds to an unsigned 8-bit +integer ranging from 0 to 255. It is generally recommended to use `Int8` +instead of `Byte` when performing math operations, however, `Byte`s are used in +API methods for `Text` and `Path` that deal with raw binary data, such as +`Path.read_bytes()` and `Text.utf8_bytes()`. Byte literals can be written as an +integer with a `[B]` suffix, e.g. `255[B]`. + +# Byte Methods + +## `random` + +**Description:** +Generates a random byte value in the specified range. + +**Usage:** +```tomo +random(min: Byte = Byte.min, max: Byte = Byte.max) -> Byte +``` + +**Parameters:** + +- `min`: The minimum value to generate (inclusive). +- `max`: The maximum value to generate (inclusive). + +**Returns:** +A random byte chosen with uniform probability from within the given range +(inclusive). If `min` is greater than `max`, an error will be raised. + +**Example:** +```tomo +>> Byte.random() += 42[B] +``` -- cgit v1.2.3