Skip to content

Commit f10d96a

Browse files
committed
- added documentation for deterministic random
1 parent c8cad25 commit f10d96a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ t.expand("There once was a man named #city.reverse.title#, who came from the cit
312312
> The original implementation at Tracery.io a couple of has modifiers that allows prefixing a/an to words, pluralization, caps etc. This library replicates all the original modifiers and adds two important new ones: the modifier ".n" can be used to add a newline to the document and the modifier ".k(formula)" can be used for making calculations. Currently calculations always return float numbers and the following operations are supported:
313313
- basic binary operations: `+`,`-`, `*`, `/`
314314
- brackets for grouping: `()`
315-
- complex unary oprations: `sin(rad)`, `cos(rad)`, `rand(range)`
315+
- complex unary oprations: `sin(rad)`, `cos(rad)`, `rand(range)`, `sqrt(value)`
316316

317317
Due to how the parsing consumes brackets only bracket-less operations can be performed directly. Otherwise the syntax is as follows:
318318

@@ -446,6 +446,23 @@ t.expand("#letter#")
446446

447447
****
448448

449+
## Advanced Usage: Deterministic Execution
450+
451+
In order to allow for replicable results, a deterministic random generator can be chosen. This is achieved by setting the option `isDeterministic` to true and supplying a random seed with the option `seed`. Both can be found in `TraceryOptions`. Here is an example:
452+
453+
```swift
454+
455+
let options = TraceryOptions.defaultSet
456+
options.seed = 15
457+
options.isDeterministic = true
458+
459+
Tracery.init(options, lines: strings)
460+
461+
```
462+
463+
The above example would expand a grammar similarly over multiple executions.
464+
465+
449466
## Advanced Usage: Custom Content Selectors
450467

451468
We know that a rule can have multiple candidates. By default, Tracery chooses a candidate option randomly, but the selection process is guaranteed to be strictly uniform.

0 commit comments

Comments
 (0)