Skip to content

Commit 1b38452

Browse files
Update comment
1 parent b68d103 commit 1b38452

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

examples/random_greeter.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@
1919
@random_greeter.handler()
2020
async def greet(ctx: Context, name: str) -> str:
2121

22+
# ctx.random() returns a Python Random instance seeded deterministically.
23+
# By using ctx.random() you don't write entries in the journal, while getting the same generated values on retries.
24+
25+
# You can ctx.random() to generate random numbers using ctx.random().randint()
2226
random_number = ctx.random().randint(0, 100)
27+
28+
# Or random bytes using ctx.random().randbytes()
29+
random_bytes = ctx.random().randbytes(10)
30+
31+
# Use ctx.uuid() to generate a UUID v4 seeded deterministically
32+
# As with ctx.random(), this won't write entries in the journal
2333
random_uuid = ctx.uuid()
2434

25-
return f"Hello {name} with random number {random_number} and uuid {random_uuid}!"
35+
return f"Hello {name} with random number {random_number}, random bytes {random_bytes} and uuid {random_uuid}!"

0 commit comments

Comments
 (0)