diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-15 17:00:25 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-15 17:00:25 -0400 |
| commit | 3cbc62ee43737e3afae0dd2e6597ff703689634e (patch) | |
| tree | fa8e641e1dfde505857cb81bb27f8285956876a7 | |
| parent | 0060686646561b099e3c8b9908d82cc22eba433a (diff) | |
Add docs on bytes
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/bytes.md | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/docs/README.md b/docs/README.md index 13401f32..20b18210 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,6 +19,7 @@ Information about Tomo's built-in types can be found here: - [Arrays](arrays.md) - [Booleans](booleans.md) +- [Bytes](bytes.md) - [Channels](channels.md) - [Enums](enums.md) - [Floating point numbers](nums.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] +``` |
