rv


Namerv JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/thorwhalen/uu/tree/master/rv
SummaryUtils to work with randomness
upload_time2024-01-23 09:37:00
maintainer
docs_urlNone
authorThor Whalen
requires_python
licenseapache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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']




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thorwhalen/uu/tree/master/rv",
    "name": "rv",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Thor Whalen",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/71/d3/4ae864a3a131c7d0a497f9cca25456145c813484c0f97b27cefe9a1d1dd7/rv-0.0.6.tar.gz",
    "platform": "any",
    "description": "# rv\n\nUtils to work with randomness\n\nTo install:\t```pip install rv```\n\n\n# Examples\n\n## random_word\n\nMake a random word by concatenating randomly drawn elements from alphabet together\n\n    >>> t = random_word(4, 'abcde');  # e.g. 'acae'\n    >>> t = random_word(5, ['a', 'b', 'c']);  # e.g. 'cabba'\n    >>> t = random_word(4, [[1, 2, 3], [40, 50], [600], [7000]]);  # e.g. [40, 50, 7000, 7000, 1, 2, 3]\n    >>> t = random_word(4, [1, 2, 3, 4]);  # e.g. 13 (because adding numbers...)\n    >>> # ... sometimes it's what you want:\n    >>> t = random_word(4, [2 ** x for x in range(8)]);  # e.g. 105 (binary combination)\n    >>> t = random_word(4, [1, 2, 3, 4], concat_func=lambda x, y: str(x) + str(y));  # e.g. '4213'\n    >>> t = random_word(4, [1, 2, 3, 4], concat_func=lambda x, y: int(str(x) + str(y)));  # e.g. 3432\n\n\n## random_romatted_str_gen\n\nRandom formatted string generator\n\nThe 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.\n\n    >>> list(random_formatted_str_gen('root/{}/{}_{}.test', (2, 5), 'abc', n=5))\n    [('root/acba/bb_abc.test',),\n        ('root/abcb/cbbc_ca.test',),\n        ('root/ac/ac_cc.test',),\n        ('root/aacc/ccbb_ab.test',),\n        ('root/aab/abb_cbab.test',)]\n\nExample with automatic specification: \n\n    >>> list(random_formatted_str_gen('root/{}/{}_{}.test', (3, 4), 'a', n=2))\n    [('root/aaa/aaa_aaa.test',), ('root/aaa/aaa_aaa.test',)]\n\nExample with manual specification\n\n    >>> list(random_formatted_str_gen('indexed field: {0}: named field: {name}', (2, 3), 'z', n=1))\n    [('indexed field: zz: named field: zz',)]\n\n\n## Utils\n\nGet the \"parameter\" indices/names of the format_string\n\n    >>> from rv import format_params_in_str_format\n    >>> format_string = '{0} (no 1) {2}, and {0} is a duplicate, {} is unnamed and {name} is string-named'\n    >>> format_params_in_str_format(format_string)\n    [0, 2, 0, None, 'name']\n\n\n\n",
    "bugtrack_url": null,
    "license": "apache-2.0",
    "summary": "Utils to work with randomness",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/thorwhalen/uu/tree/master/rv"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b687efdee8da8f9ca0c603905d422df50ccfa9339a32c4eaff35aff233b3e0c",
                "md5": "5d123783f68af7c469472bf58a996522",
                "sha256": "faa9d78ee1f6a164669860ba9658dbc444753d78f68b0d9632f8bd9ac909fb03"
            },
            "downloads": -1,
            "filename": "rv-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5d123783f68af7c469472bf58a996522",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9922,
            "upload_time": "2024-01-23T09:36:59",
            "upload_time_iso_8601": "2024-01-23T09:36:59.235186Z",
            "url": "https://files.pythonhosted.org/packages/6b/68/7efdee8da8f9ca0c603905d422df50ccfa9339a32c4eaff35aff233b3e0c/rv-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "71d34ae864a3a131c7d0a497f9cca25456145c813484c0f97b27cefe9a1d1dd7",
                "md5": "5b6115fd3a69351442c942c3841409d1",
                "sha256": "49a683cede22dde67ea5d8c7a99697883d621c1c205111f46021eb80c60e2bb7"
            },
            "downloads": -1,
            "filename": "rv-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "5b6115fd3a69351442c942c3841409d1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9142,
            "upload_time": "2024-01-23T09:37:00",
            "upload_time_iso_8601": "2024-01-23T09:37:00.475344Z",
            "url": "https://files.pythonhosted.org/packages/71/d3/4ae864a3a131c7d0a497f9cca25456145c813484c0f97b27cefe9a1d1dd7/rv-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-23 09:37:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thorwhalen",
    "github_project": "uu",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rv"
}
        
Elapsed time: 0.36765s