Skip to content

Commit a9da7c8

Browse files
committed
Update recommended usage in documentation.
1 parent be3380c commit a9da7c8

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

docs/src/index.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,18 @@ DocTestSetup = quote
2828
end
2929
```
3030

31-
To start generating random numbers with ChaChaCiphers, create a new keystream
32-
with a function like [`ChaCha20Stream`](@ref) or [`ChaCha12Stream`](@ref):
31+
To start generating random numbers, create a new keystream by constructing a
32+
[`ChaChaStream`](@ref) instance:
3333

3434
```jldoctest
3535
julia> using ChaChaCiphers
3636
37-
julia> rng = ChaCha20Stream();
37+
julia> rng = ChaChaStream();
3838
```
3939

4040
This will generate a keystream using a key sampled from the operating system's
41-
random stream. Alternatively, you can explicitly specify a `key` and `nonce` as
42-
follows:
43-
44-
```jldoctest
45-
julia> key = UInt32.([
46-
0xe2e39848, 0x70bb974d, 0x845f88b4, 0xb30725e4,
47-
0x15c309dc, 0x72d545bb, 0x466e99e3, 0x6a759f91
48-
]);
49-
50-
julia> nonce = UInt64(0);
51-
52-
julia> rng = ChaCha20Stream(key, nonce);
53-
```
54-
55-
After generating a keystream, you can supply it as the `rng` parameter to
56-
`Random` functions like `rand` and `randn`:
41+
random stream. You can then supply `rng` as a parameter to `Random` functions,
42+
like `rand` and `randn`:
5743

5844
```jldoctest
5945
julia> using Random
@@ -70,6 +56,23 @@ julia> randn(rng, Float32, 3)
7056

7157
Review the API documentation for more details.
7258

59+
## Advanced usage
60+
61+
In general, we recommend instantiating `ChaChaStream` by simply calling
62+
`ChaChaStream()`. However, in some cases you may wish to explicitly supply a key
63+
to construct your stream, which you can do as follows:
64+
65+
```jldoctest
66+
julia> key = UInt32.([
67+
0xe2e39848, 0x70bb974d, 0x845f88b4, 0xb30725e4,
68+
0x15c309dc, 0x72d545bb, 0x466e99e3, 0x6a759f91
69+
]);
70+
71+
julia> rng = ChaCha20Stream(key);
72+
```
73+
74+
In this mode, the key will act as a seed for the random number generator.
75+
7376
## About ChaCha
7477

7578
ChaCha was first introduced as a variant of the Salsa20 stream cipher by Daniel

0 commit comments

Comments
 (0)