{"id":15043584,"url":"https://github.com/sudo-rushil/randtest","last_synced_at":"2026-02-12T00:31:35.603Z","repository":{"id":57459937,"uuid":"225249303","full_name":"sudo-rushil/randtest","owner":"sudo-rushil","description":"Quick and accurate determinations of the randomness of a sequence","archived":false,"fork":false,"pushed_at":"2019-12-02T23:33:11.000Z","size":173,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-12T10:20:48.249Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/randtest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudo-rushil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-01T23:55:22.000Z","updated_at":"2024-01-19T13:08:29.000Z","dependencies_parsed_at":"2022-09-15T20:21:40.120Z","dependency_job_id":null,"html_url":"https://github.com/sudo-rushil/randtest","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-rushil%2Frandtest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-rushil%2Frandtest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-rushil%2Frandtest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-rushil%2Frandtest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudo-rushil","download_url":"https://codeload.github.com/sudo-rushil/randtest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858873,"owners_count":20684062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T20:49:18.404Z","updated_at":"2026-02-12T00:31:35.597Z","avatar_url":"https://github.com/sudo-rushil.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RandTest\n\nA lightweight package for quick and accurate determinations of the randomness of a sequence.\n\n# Overview\n\nIdentifying random patterns, and conversely, ordered patterns, is a major tool with applicability to a wide variety of fields, from mathematical analysis to cybersecurity. Random Test looks for randomness in sequences of numbers by searching for patterns which are inherently unpredictable. It uses an exponentially-decaying moment prediction to determine the net deviation between the predicted and actual elements of a sequence. In tests, this led to a net **predictive accuracy of 99.85% for nonrandom sequences and 96.82% for random sequences**. Additionally, this package is able to provide these predictions in under a millisecond for sequences shorter than 10 elements and under 100 milliseconds for sequences shorter than 1000 elements.\n\n## Requirements\n\nRandTest is built for Python 3. It has only one requirement:\n\n    - Numpy\n\n# Installation\n\nTo download randtest, use PyPI via pip:\n\n```sh\npip install randtest\n```\n\nAlternatively, you can clone this Github repository and build from source:\n\n```sh\ngit clone https://github.com/sudo-rushil/randtest\ncd randtest\npython setup.py install\n```\n\nVerify your installation by running\n\n```Python\n\u003e\u003e\u003e import randtest\n\u003e\u003e\u003e randtest.random_score([0, 1, 2, 3])\n'False'\n```\n\n# Examples\n\nRandTest is extremely simple to use. You only need to input either a list or a 1D Numpy array of numbers. The prediction returns `False` if the sequence is ordered and `True` if the sequence is random.\n\n```Python\nimport numpy as np\nimport randtest as rt\n\nordered_sequence = np.arange(10)\nrandom_sequence = np.random.randint(10, size=10)\n\nprint(rt.random_score(ordered_sequence))\n\nprint(rt.random_score(random_sequence))\n```\n\n\u003e False\n\n\u003e True \n\n# Documentation\n\nRandTest is a very lightweight package. It has polymorphism support; you can pass either a list or a 1D Numpy array without any effort. It is also extremely fast, returning predictions in under 100 milliseconds, even in extreme cases.\n\n## Algorithm\n\nRandTest identifies randomness by one of its byworded properties - unpredictability. It uses the conformance of a sequence to a continuously generated predicted model as a measure of how unpredictable - how random - that sequence is.\n\nFor any sequence of numbers \u003cimg src=\"/tex/65ed4b231dcf18a70bae40e50d48c9c0.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=13.340053649999989pt height=14.15524440000002pt/\u003e, with \u003cimg src=\"/tex/77a3b857d53fb44e33b53e4c8b68351a.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=5.663225699999989pt height=21.68300969999999pt/\u003e ranging from \u003cimg src=\"/tex/29632a9bf827ce0200454dd32fc3be82.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=8.219209349999991pt height=21.18721440000001pt/\u003e to \u003cimg src=\"/tex/efcf8d472ecdd2ea56d727b5746100e3.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=38.17727759999999pt height=21.18721440000001pt/\u003e, where \u003cimg src=\"/tex/55a049b8f161ae7cfeb0197d75aff967.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=9.86687624999999pt height=14.15524440000002pt/\u003e is the length of the sequence, we can compute the element-wise gradients as a new sequence, \u003cimg src=\"/tex/3625ab7c1b30dcd3c08e10061c91ce68.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=114.01535969999999pt height=22.465723500000017pt/\u003e, which has length \u003cimg src=\"/tex/efcf8d472ecdd2ea56d727b5746100e3.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=38.17727759999999pt height=21.18721440000001pt/\u003e. \nFrom here, we can apply exponential scaling, sum these gradients, and normalize to obtain the predicted gradient, \u003cimg src=\"/tex/c88565636040fa245dadbf8378667fc4.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=30.51384929999999pt height=31.141535699999984pt/\u003e.\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"/tex/a3b25a0334c90fcf366078c7e4bdaaf5.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=155.72099895pt height=45.82666275pt/\u003e\u003c/p\u003e\n\nThen, the predicted value \u003cimg src=\"/tex/28d65fd9ccc424e34ec4f277701115a2.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=16.81517804999999pt height=22.831056599999986pt/\u003e is \u003cimg src=\"/tex/5bd075809c77195b473bbb706e536c98.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=85.06867215pt height=31.141535699999984pt/\u003e.\n\nTo compute the numerical randomness score of a sequence \u003cimg src=\"/tex/65ed4b231dcf18a70bae40e50d48c9c0.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=13.340053649999989pt height=14.15524440000002pt/\u003e, with \u003cimg src=\"/tex/77a3b857d53fb44e33b53e4c8b68351a.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=5.663225699999989pt height=21.68300969999999pt/\u003e ranging between \u003cimg src=\"/tex/29632a9bf827ce0200454dd32fc3be82.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=8.219209349999991pt height=21.18721440000001pt/\u003e and \u003cimg src=\"/tex/55a049b8f161ae7cfeb0197d75aff967.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=9.86687624999999pt height=14.15524440000002pt/\u003e, we take the sum\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"/tex/caade0fdcb3a04fd29e36c52651d9451.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=93.9936063pt height=45.2741091pt/\u003e\u003c/p\u003e\n\nwhere the predicted value \u003cimg src=\"/tex/b22ec94b5bdaa79af222bfafdd3f2110.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=15.95518319999999pt height=22.831056599999986pt/\u003e comes from the sliced subsequence of \u003cimg src=\"/tex/44bc9d542a92714cac84e01cbbb7fd61.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=8.68915409999999pt height=14.15524440000002pt/\u003e containing all elements up to \u003cimg src=\"/tex/63bb9849783d01d91403bc9a5fea12a2.svg?invert_in_darkmode\u0026sanitize=true\" align=middle width=9.075367949999992pt height=22.831056599999986pt/\u003e.\n\nIn the RandTest implementation, this randomness score is converted into a prediction by comparision with an empirically determined threshold, which is chosen to maximize the combined precision and sensitivity of the classifier on both random and ordered sequences.\n\n## API\n\nRandTest contains a single function, `random_score`. This returns `True` if the input sequence *is* random. This means it can be integrated directly into your current control flow.\n\n```Python\nimport numpy as np\nfrom randtest import random_score\n\n# Ordered sequences\nrandom_score(np.arange(10)) # False\nrandom_score(np.geomspace(1, 27, num=4)) # False\nrandom_score([0, 1, 2, 3, 4, 5]) # False\n\n# Random sequences\nrandom_score(np.random.randint(100, size=10)) # True\nrandom_score([7, 12, 14, 88, 9]) # True\n```\n\nThis function has an optional input of `raw=True`, which enables you to directly access the randomness metric as defined above. However, we reccomend you do not pass this in production environments, as the function has already been thresholded on over 200,000 examples.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudo-rushil%2Frandtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudo-rushil%2Frandtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudo-rushil%2Frandtest/lists"}