Skip to main content

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

rv-0.0.6.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

rv-0.0.6-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file rv-0.0.6.tar.gz.

File metadata

  • Download URL: rv-0.0.6.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for rv-0.0.6.tar.gz
Algorithm Hash digest
SHA256 49a683cede22dde67ea5d8c7a99697883d621c1c205111f46021eb80c60e2bb7
MD5 5b6115fd3a69351442c942c3841409d1
BLAKE2b-256 71d34ae864a3a131c7d0a497f9cca25456145c813484c0f97b27cefe9a1d1dd7

See more details on using hashes here.

File details

Details for the file rv-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: rv-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for rv-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 faa9d78ee1f6a164669860ba9658dbc444753d78f68b0d9632f8bd9ac909fb03
MD5 5d123783f68af7c469472bf58a996522
BLAKE2b-256 6b687efdee8da8f9ca0c603905d422df50ccfa9339a32c4eaff35aff233b3e0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page