Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
6617b0f1
Commit
6617b0f1
authored
3 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
v2.17.21
parent
748f8353
No related branches found
Branches containing commit
Tags
v2.17.21
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
satella/random.py
+10
-4
10 additions, 4 deletions
satella/random.py
with
10 additions
and
4 deletions
satella/random.py
+
10
−
4
View file @
6617b0f1
import
typing
as
tp
import
os
import
os
import
random
import
random
import
typing
as
tp
import
typing
as
tp
...
@@ -8,22 +9,27 @@ __all__ = ['shuffle_together', 'random_binary', 'random_word']
...
@@ -8,22 +9,27 @@ __all__ = ['shuffle_together', 'random_binary', 'random_word']
from
satella.coding.typing
import
T
from
satella.coding.typing
import
T
def
random_word
(
length
:
int
,
choice
:
T
=
string
.
ascii_lowercase
,
def
random_word
(
length
:
int
,
choice
:
tp
.
Sequence
[
T
]
=
string
.
ascii_lowercase
,
join_fun
:
tp
.
Callable
[[
T
,
...],
T
]
=
lambda
*
args
:
''
.
join
(
args
)):
join_fun
:
tp
.
Callable
[[
tp
.
List
[
T
]],
T
]
=
lambda
args
:
''
.
join
(
args
))
->
\
tp
.
Sequence
[
T
]:
"""
"""
Build and return a random word of provided length.
Build and return a random word of provided length.
The word will be built by calling join_fun with length of arguments picked
The word will be built by calling join_fun with length of arguments picked
at random from choice.
at random from choice.
Best used with strings. Provide a word length, a string to choose from as choice (defaults
to string.ascii_lowercase). Will return by default a string (which coincidentally
happens to be a sequence of strings, albeit one-character ones).
:param length: length of the word
:param length: length of the word
:param choice: a range of characters to use. By default is string.ascii_lowercase
:param choice: a range of characters to use. By default is string.ascii_lowercase
:param join_fun: an argument to be called with randomly picked
characters as *arg
s.
:param join_fun: an argument to be called with
a list of
randomly picked
value
s.
Defaults to
''
.join(args), so your T must be a string. If you
'
re passing a
Defaults to
''
.join(args), so your T must be a string. If you
'
re passing a
different type, remember to alter this function because the default one expects strings!
different type, remember to alter this function because the default one expects strings!
:return: a random word
:return: a random word
"""
"""
return
join_fun
(
*
(
random
.
choice
(
choice
)
for
_
in
range
(
length
)
)
)
return
join_fun
(
[
random
.
choice
(
choice
)
for
_
in
range
(
length
)
]
)
def
random_binary
(
length
:
int
)
->
bytes
:
def
random_binary
(
length
:
int
)
->
bytes
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment