@@ -175,11 +175,16 @@ Quick Reference
175175#### Infinite Iteration
176176| Iterator | Description | Code Snippet |
177177| -------------------------| ----------------------------| ------------------------------------|
178- | [ ` booleans ` ] ( #Booleans ) | Generate random booleans | ` infinite.booleans([repetitions]) ` |
179178| [ ` count ` ] ( #Count ) | Count sequentially forever | ` infinite.count([start], [step]) ` |
180179| [ ` cycle ` ] ( #Cycle ) | Cycle through a collection | ` infinite.cycle(iterable) ` |
181180| [ ` repeat ` ] ( #Repeat-1 ) | Repeat an item forever | ` infinite.repeat(item) ` |
182181
182+ #### Random Iteration
183+ | Iterator | Description | Code Snippet |
184+ | -----------------------------| ----------------------------| ------------------------------------|
185+ | [ ` booleans ` ] ( #Booleans ) | Generate random booleans | ` random.booleans([repetitions]) ` |
186+ | [ ` percentage ` ] ( #Percentage ) | Generate random percentage | ` random.percentage([repetitions]) ` |
187+
183188#### Math Iteration
184189| Iterator | Description | Sync Code Snippet | Async Code Snippet |
185190| --------------------------------------------| ---------------------------------| ---------------------------------------------------| --------------------------------------------------------|
@@ -253,14 +258,15 @@ Quick Reference
253258
254259### Stream and AsyncStream Iteration Tools
255260#### Stream Sources
256- | Source | Description | Sync Code Snippet | Async Code Snippet |
257- | ------------------------------| -------------------------------------| ------------------------------------| -----------------------------------------|
258- | [ ` of ` ] ( #of ) | Create a stream from an iterable | ` Stream.of(iterable) ` | ` AsyncStream.of(iterable) ` |
259- | [ ` ofCount ` ] ( #of-count ) | Create an infinite count stream | ` Stream.ofCount([start], [step]) ` | ` AsyncStream.ofCount([start], [step]) ` |
260- | [ ` ofBooleans ` ] ( #of-booleans ) | Create an infinite booleans stream | ` Stream.ofBooleans([repetitions]) ` | ` AsyncStream.ofBooleans([repetitions]) ` |
261- | [ ` ofCycle ` ] ( #of-cycle ) | Create an infinite cycle stream | ` Stream.ofCycle(iterable) ` | ` AsyncStream.ofCycle(iterable) ` |
262- | [ ` ofEmpty ` ] ( #of-empty ) | Create an empty stream | ` Stream.ofEmpty() ` | ` AsyncStream.ofEmpty() ` |
263- | [ ` ofRepeat ` ] ( #of-repeat ) | Create an infinite repeating stream | ` Stream.ofRepeat(item) ` | ` AsyncStream.ofRepeat(item) ` |
261+ | Source | Description | Sync Code Snippet | Async Code Snippet |
262+ | ----------------------------------| -------------------------------------| ------------------------------------| -----------------------------------------|
263+ | [ ` of ` ] ( #of ) | Create a stream from an iterable | ` Stream.of(iterable) ` | ` AsyncStream.of(iterable) ` |
264+ | [ ` ofCount ` ] ( #of-count ) | Create an infinite count stream | ` Stream.ofCount([start], [step]) ` | ` AsyncStream.ofCount([start], [step]) ` |
265+ | [ ` ofBooleans ` ] ( #of-booleans ) | Create booleans stream | ` Stream.ofBooleans([repetitions]) ` | ` AsyncStream.ofBooleans([repetitions]) ` |
266+ | [ ` ofCycle ` ] ( #of-cycle ) | Create an infinite cycle stream | ` Stream.ofCycle(iterable) ` | ` AsyncStream.ofCycle(iterable) ` |
267+ | [ ` ofEmpty ` ] ( #of-empty ) | Create an empty stream | ` Stream.ofEmpty() ` | ` AsyncStream.ofEmpty() ` |
268+ | [ ` ofPercentage ` ] ( #of-percentage ) | Create percentage stream | ` Stream.ofPercentage(item) ` | ` AsyncStream.ofPercentage(item) ` |
269+ | [ ` ofRepeat ` ] ( #of-repeat ) | Create an infinite repeating stream | ` Stream.ofRepeat(item) ` | ` AsyncStream.ofRepeat(item) ` |
264270
265271#### Stream Operations
266272| Operation | Description | Code Snippet |
@@ -1030,6 +1036,37 @@ for (const item of infinite.repeat('bla')) {
10301036// bla, bla, bla, bla, bla, ...
10311037```
10321038
1039+ ## Random Iteration
1040+
1041+ ### Percentage
1042+ Generate random percentage values.
1043+
1044+ ```
1045+ function* percentage(repetitions?: number): Iterable<number>
1046+ ```
1047+
1048+ If ` repetitions ` is provided, generates exactly that many numbers. If not provided, generates numbers infinitely.
1049+
1050+ ``` typescript
1051+ import { random } from ' itertools-ts' ;
1052+
1053+ for (const num of infinite .percentage (5 )) {
1054+ console .log (num );
1055+ }
1056+ // 0.7745835631877125, 0.6368758907434469, 0.6465445462428422, 0.49809604559145615, 0.7009703411939564 (random values)
1057+
1058+ for (const num of infinite .percentage ()) {
1059+ console .log (num );
1060+ }
1061+ // 0.7745835631877125, 0.6368758907434469, 0.6465445462428422... (random values)
1062+
1063+ // Async version
1064+ for await (const num of infinite .percentageAsync (5 )) {
1065+ console .log (num );
1066+ }
1067+ // 0.7745835631877125, 0.6368758907434469, 0.6465445462428422... (random values)
1068+ ```
1069+
10331070## Math Iteration
10341071
10351072### Running Average
0 commit comments