Utils to work with randomness
Project description
rv
Utils to work with randomness
To install: pip install rv
Examples
random_word
Make a random word by concatenating randomly drawn elements from alphabet together
>>> t = random_word(4, 'abcde'); # e.g. 'acae'
>>> t = random_word(5, ['a', 'b', 'c']); # e.g. 'cabba'
>>> t = random_word(4, [[1, 2, 3], [40, 50], [600], [7000]]); # e.g. [40, 50, 7000, 7000, 1, 2, 3]
>>> t = random_word(4, [1, 2, 3, 4]); # e.g. 13 (because adding numbers...)
>>> # ... sometimes it's what you want:
>>> t = random_word(4, [2 ** x for x in range(8)]); # e.g. 105 (binary combination)
>>> t = random_word(4, [1, 2, 3, 4], concat_func=lambda x, y: str(x) + str(y)); # e.g. '4213'
>>> t = random_word(4, [1, 2, 3, 4], concat_func=lambda x, y: int(str(x) + str(y))); # e.g. 3432
random_romatted_str_gen
Random formatted string generator
The following will be made not random (by restricting the constraints to "no choice". This is so that we get consistent outputs to assert for the doc test.
>>> list(random_formatted_str_gen('root/{}/{}_{}.test', (2, 5), 'abc', n=5))
[('root/acba/bb_abc.test',),
('root/abcb/cbbc_ca.test',),
('root/ac/ac_cc.test',),
('root/aacc/ccbb_ab.test',),
('root/aab/abb_cbab.test',)]
Example with automatic specification:
>>> list(random_formatted_str_gen('root/{}/{}_{}.test', (3, 4), 'a', n=2))
[('root/aaa/aaa_aaa.test',), ('root/aaa/aaa_aaa.test',)]
Example with manual specification
>>> list(random_formatted_str_gen('indexed field: {0}: named field: {name}', (2, 3), 'z', n=1))
[('indexed field: zz: named field: zz',)]
Utils
Get the "parameter" indices/names of the format_string
>>> from rv import format_params_in_str_format
>>> format_string = '{0} (no 1) {2}, and {0} is a duplicate, {} is unnamed and {name} is string-named'
>>> format_params_in_str_format(format_string)
[0, 2, 0, None, 'name']
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rv-0.0.7.tar.gz.
File metadata
- Download URL: rv-0.0.7.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fafc7324b8bc63f83712c06f5c4a60cb18e142468d8646aef5050ede57e454bf
|
|
| MD5 |
8e83b3775273f5fa28d03dcc8d5d1d46
|
|
| BLAKE2b-256 |
2e2866b5b98229b3c66758c9446a2c82a5576de72d1b5da0d400f3ec65b5e85c
|
File details
Details for the file rv-0.0.7-py3-none-any.whl.
File metadata
- Download URL: rv-0.0.7-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9541a9495d18c1dc6f96dde7158f433301826ba24cc1c0ac02d63a85cbfb8fd
|
|
| MD5 |
2870be2a244a00de3d68148d50ebe8a3
|
|
| BLAKE2b-256 |
de4fd1a1b5130730e3674e878ea9ebcc4f368fecac750666e78599a94de331c0
|