aboutsummaryrefslogtreecommitdiff
path: root/examples/random
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 14:20:18 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 14:20:18 -0400
commit2bb2ff871fa1761478442bec5f6a32c9428360a1 (patch)
tree9b73df7a0c50c02353ae7bca7c2cd54788ef0077 /examples/random
parent59845e610f2c90474f34079d27b5f1e07071ded4 (diff)
Change method calls to use `foo.baz()` instead of `foo:baz()`
Diffstat (limited to 'examples/random')
-rw-r--r--examples/random/README.md26
-rw-r--r--examples/random/random.tm26
2 files changed, 26 insertions, 26 deletions
diff --git a/examples/random/README.md b/examples/random/README.md
index 6233c1ba..d9983ab7 100644
--- a/examples/random/README.md
+++ b/examples/random/README.md
@@ -17,14 +17,14 @@ a Tomo program launches.
This documentation provides details on RNG functions available in the API.
Arrays also have some methods which use RNG values:
-`array:shuffle()`, `array:shuffled()`, `array:random()`, and `array:sample()`.
+`array.shuffle()`, `array.shuffled()`, `array.random()`, and `array.sample()`.
- [`func bool(rng: RNG, p: Num = 0.5 -> Bool)`](#bool)
- [`func byte(rng: RNG -> Byte)`](#byte)
- [`func bytes(rng: RNG, count: Int -> [Byte])`](#bytes)
- [`func copy(rng: RNG -> RNG)`](#copy)
- [`func int(rng: RNG, min: Int, max: Int -> Int)`](#int`, `int64`, `int32`, `int16`, `int8)
-- [`func new(seed: [Byte] = (/dev/urandom):read_bytes(40)! -> RNG)`](#new)
+- [`func new(seed: [Byte] = (/dev/urandom).read_bytes(40)! -> RNG)`](#new)
- [`func num(rng: RNG, min: Num = 0.0, max: Num = 1.0 -> Num)`](#num`, `num32)
-------------
@@ -46,9 +46,9 @@ func bool(rng: RNG, p: Num = 0.5 -> Bool)
**Example:**
```tomo
->> random:bool()
+>> random.bool()
= no
->> random:bool(1.0)
+>> random.bool(1.0)
= yes
```
@@ -68,7 +68,7 @@ A random byte (0-255).
**Example:**
```tomo
->> random:byte()
+>> random.byte()
= 103[B]
```
@@ -89,7 +89,7 @@ An array of length `count` random bytes with uniform random distribution (0-255)
**Example:**
```tomo
->> random:bytes(4)
+>> random.bytes(4)
= [135[B], 169[B], 103[B], 212[B]]
```
@@ -111,13 +111,13 @@ A copy of the given RNG.
**Example:**
```tomo
>> rng := RNG.new([])
->> copy := rng:copy()
+>> copy := rng.copy()
->> rng:bytes(10)
+>> rng.bytes(10)
= [224[B], 102[B], 190[B], 59[B], 251[B], 50[B], 217[B], 170[B], 15[B], 221[B]]
# The copy runs in parallel to the original RNG:
->> copy:bytes(10)
+>> copy.bytes(10)
= [224[B], 102[B], 190[B], 59[B], 251[B], 50[B], 217[B], 170[B], 15[B], 221[B]]
```
@@ -144,7 +144,7 @@ is greater than `max`, an error will be raised.
**Example:**
```tomo
->> random:int(1, 10)
+>> random.int(1, 10)
= 8
```
@@ -154,7 +154,7 @@ is greater than `max`, an error will be raised.
Return a new random number generator.
```tomo
-func new(seed: [Byte] = (/dev/urandom):read_bytes(40)! -> RNG)
+func new(seed: [Byte] = (/dev/urandom).read_bytes(40)! -> RNG)
```
- `seed`: The seed use for the random number generator. A seed length of 40
@@ -167,7 +167,7 @@ A new random number generator.
**Example:**
```tomo
>> my_rng := RNG.new([1[B], 2[B], 3[B], 4[B]])
->> my_rng:bool()
+>> my_rng.bool()
= yes
```
@@ -191,6 +191,6 @@ A floating point number uniformly chosen from the range `[min, max]`
**Example:**
```tomo
->> random:num(1, 10)
+>> random.num(1, 10)
= 9.512830439975572
```
diff --git a/examples/random/random.tm b/examples/random/random.tm
index 95d2f9fe..1f60aff0 100644
--- a/examples/random/random.tm
+++ b/examples/random/random.tm
@@ -79,9 +79,9 @@ struct RandomNumberGenerator(_chacha:chacha_ctx, _random_bytes:[Byte]=[]; secret
func bool(rng:&RandomNumberGenerator, probability=0.5 -> Bool):
if probability == 0.5:
- return rng:byte() < 0x80
+ return rng.byte() < 0x80
else:
- return rng:num(0., 1.) < 0.5
+ return rng.num(0., 1.) < 0.5
func int64(rng:&RandomNumberGenerator, min=Int64.min, max=Int64.max -> Int64):
fail("Random minimum value $min is larger than the maximum value $max") if min > max
@@ -188,7 +188,7 @@ struct RandomNumberGenerator(_chacha:chacha_ctx, _random_bytes:[Byte]=[]; secret
}
func num32(rng:&RandomNumberGenerator, min=Num32(0.), max=Num32(1.) -> Num32):
- return Num32(rng:num(Num(min), Num(max)))
+ return Num32(rng.num(Num(min), Num(max)))
func int(rng:&RandomNumberGenerator, min:Int, max:Int -> Int):
return inline C : Int {
@@ -228,13 +228,13 @@ struct RandomNumberGenerator(_chacha:chacha_ctx, _random_bytes:[Byte]=[]; secret
func main():
>> rng := RandomNumberGenerator.new()
- >> rng:num()
- >> rng:num()
- >> rng:num()
- >> rng:num(0, 100)
- >> rng:byte()
- >> rng:bytes(20)
- # >> rng:int(1, 100)
- # >> rng:int(1, 100)
- # >> rng:int(1, 100)
- # >> rng:int(1, 100)
+ >> rng.num()
+ >> rng.num()
+ >> rng.num()
+ >> rng.num(0, 100)
+ >> rng.byte()
+ >> rng.bytes(20)
+ # >> rng.int(1, 100)
+ # >> rng.int(1, 100)
+ # >> rng.int(1, 100)
+ # >> rng.int(1, 100)