Skip to content

Commit 849d6ac

Browse files
committed
Added Stream.randint method
1 parent fcf5c08 commit 849d6ac

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ __pycache__/
22
build/
33
dist/
44
java_stream.egg-info/
5+
main.py

stream/stream.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from functools import cmp_to_key
2+
import random
23

34
from .iterators import IteratorUtils
45
from .optional import Optional
@@ -96,6 +97,17 @@ def concat(*streams):
9697
'''
9798
return Stream(IteratorUtils.concat(*streams))
9899

100+
@staticmethod
101+
def randint(lower, upper):
102+
'''
103+
Returns an infinite stream of random integer in range [a, b], including both end points.
104+
105+
:param int lower: min value for random numbers
106+
:param int upper: max value for random numbers
107+
:return: the infinite random stream
108+
'''
109+
return Stream.generate(lambda: random.randint(lower, upper))
110+
99111
"""
100112
Normal Methods
101113
"""

0 commit comments

Comments
 (0)