Skip to main content

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']

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.8.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rv-0.0.8-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rv-0.0.8.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rv-0.0.8.tar.gz
Algorithm Hash digest
SHA256 b65cdfb04c42918e815a80a38ec4dd048588daa22158218686d62cef29617f6e
MD5 306170b0024836a659ff526c75a5c2c0
BLAKE2b-256 11b4ea2172ca2996f976bacbf2fbb25fed420531cf97008049925566bd999437

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rv-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rv-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 cbf548e87133bb54141d44192559b6df0f1d103aefb36c26bcbba96d06d85786
MD5 f3cf624e7d4a16e9418d23507642123f
BLAKE2b-256 4afdde0a96549c0c2f8d9d0a629e30a53f85c87a2eb660ab0c006410b85fab80

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page