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
347a9ce5
Commit
347a9ce5
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
added random binary
parent
5fa2056b
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
docs/random.rst
+5
-0
5 additions, 0 deletions
docs/random.rst
satella/random.py
+17
-1
17 additions, 1 deletion
satella/random.py
tests/test_random.py
+5
-1
5 additions, 1 deletion
tests/test_random.py
with
29 additions
and
2 deletions
CHANGELOG.md
+
2
−
0
View file @
347a9ce5
# v2.14.34
*
added iterate_callable
*
added random_binary
This diff is collapsed.
Click to expand it.
docs/random.rst
+
5
−
0
View file @
347a9ce5
...
...
@@ -6,3 +6,8 @@ shuffle_together
----------------
.. autofunction:: satella.random.shuffle_together
random_binary
-------------
.. autofunction:: satella.random.random_binary
This diff is collapsed.
Click to expand it.
satella/random.py
+
17
−
1
View file @
347a9ce5
import
os
import
random
import
typing
as
tp
__all__
=
[
'
shuffle_together
'
]
__all__
=
[
'
shuffle_together
'
,
'
random_binary
'
]
def
random_binary
(
length
:
int
)
->
bytes
:
"""
Return a random bytes string of given length.
An attempt will be made to utilize /dev/random, if exists
:param length: length of string to generate
"""
if
os
.
path
.
exists
(
'
/dev/random
'
):
with
open
(
'
/dev/random
'
,
'
rb
'
)
as
f_in
:
return
f_in
.
read
(
length
)
else
:
return
bytes
([
random
.
randint
(
0
,
255
)
for
_
in
range
(
length
)])
def
shuffle_together
(
*
args
:
tp
.
Sequence
)
->
tp
.
List
[
tp
.
List
]:
...
...
This diff is collapsed.
Click to expand it.
tests/test_random.py
+
5
−
1
View file @
347a9ce5
import
unittest
from
satella.random
import
shuffle_together
from
satella.random
import
shuffle_together
,
random_binary
class
TestRandom
(
unittest
.
TestCase
):
def
test_random_binary
(
self
):
self
.
assertFalse
(
random_binary
(
0
))
self
.
assertEqual
(
len
(
random_binary
(
10
)),
10
)
def
test_random
(
self
):
a
=
[(
1
,
2
,
3
),
(
'
a
'
,
'
b
'
,
'
c
'
)]
b
=
zip
(
*
shuffle_together
(
*
a
))
...
...
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