{"id":31956010,"url":"https://github.com/cisagov/lcgit","last_synced_at":"2026-03-01T03:34:16.616Z","repository":{"id":40463556,"uuid":"184831540","full_name":"cisagov/lcgit","owner":"cisagov","description":"A pythonic Linear Congruential Generator iterator","archived":false,"fork":false,"pushed_at":"2025-12-23T13:43:14.000Z","size":1129,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-12-24T18:18:07.041Z","etag":null,"topics":["lcg","linear-congruential-generator","network","python","random"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cisagov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-05-03T23:25:31.000Z","updated_at":"2025-12-23T13:43:19.000Z","dependencies_parsed_at":"2023-12-22T16:36:14.713Z","dependency_job_id":"f2c1a0b4-53d2-47df-b738-194ab29384ad","html_url":"https://github.com/cisagov/lcgit","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/cisagov/lcgit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisagov%2Flcgit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisagov%2Flcgit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisagov%2Flcgit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisagov%2Flcgit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cisagov","download_url":"https://codeload.github.com/cisagov/lcgit/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisagov%2Flcgit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29959396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T01:47:18.291Z","status":"online","status_checked_at":"2026-03-01T02:00:07.437Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["lcg","linear-congruential-generator","network","python","random"],"created_at":"2025-10-14T14:47:10.663Z","updated_at":"2026-03-01T03:34:16.607Z","avatar_url":"https://github.com/cisagov.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lcgit 🎰 #\n\n[![GitHub Build Status](https://github.com/cisagov/lcgit/workflows/build/badge.svg)](https://github.com/cisagov/lcgit/actions)\n[![License](https://img.shields.io/github/license/cisagov/lcgit)](https://spdx.org/licenses/)\n[![CodeQL](https://github.com/cisagov/lcgit/workflows/CodeQL/badge.svg)](https://github.com/cisagov/lcgit/actions/workflows/codeql-analysis.yml)\n[![Coverage Status](https://coveralls.io/repos/github/cisagov/lcgit/badge.svg?branch=develop)](https://coveralls.io/github/cisagov/lcgit?branch=develop)\n[![Code Style](https://img.shields.io/badge/Code%20Style-black-black)](https://github.com/psf/black)\n\nDo you want to loop randomly through every item in huge sequence without\noutputting the same item twice?  Would you like to do this while keeping\nminimal state?  Then you need a\n[Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_congruential_generator)\niterator!\n\n```python\nfrom lcgit import lcg\nfrom ipaddress import ip_network\n\nfor i in lcg(ip_network(\"10.0.0.0/8\")):\n  print(i)\n```\n\nThe code above, will print out each of the 16,777,216 IPs in the `10.0.0.0/8`\nnetwork in random order.  Which is useful.  But what would be more useful is\nif you can output some now, save your state, and do some more later!\n\nThis is where `emit` comes in.  Creating an `lcg` with `emit=True` will cause\nthe iterator to emit its state along with the sequence value.  If you save\nthis state, and pass it back to a new `lcg` it will produce iterators that will\ncontinue the random sequence where you left off.\n\n```python\nfrom lcgit import lcg\nfrom ipaddress import ip_network\n\nmy_lcg = lcg(ip_network(\"192.168.1.0/24\"), emit=True)\nit = iter(my_lcg)\n# print the first 32 random values\nfor i in range(32):\n  value, state = next(it)\n  print(value)\n\n# save state, and come back later\nsave_it(state, to_something)\n```\n\nHow large is the state?  Am I going to need a flag bit for each item?  Will I\nneed to buy more RAM and disk?  How about a tuple of four integers, no matter\nhow large the sequence is!?  The `state` variable at the end of the code block\nabove would be storing something very similar to: `(149, 223, 161, 32)`\n\nTo continue the generator where we left off, you simply create a new one for\nthe same sequence, and pass in your stored `state`:\n\n```python\nrestored = load_it(from_somewhere) # (149, 223, 161, 32)\nmy_new_lcg = lcg(ip_network(\"192.168.1.0/24\"), state=restored)\n# print the remaining values\nfor i in my_new_lcg:\n  print(i)\n```\n\n`lcgit` doesn't just work with networks.  It will also work with any of the\n[Python sequence types](https://docs.python.org/3/library/stdtypes.html#typesseq).\n\n```python\nfor i in lcg(range(100_000_000_000_000)):\n  print(i)\n```\n\n## NOOICE! 🕺 ##\n\n## Contributing ##\n\nWe welcome contributions!  Please see [`CONTRIBUTING.md`](CONTRIBUTING.md) for\ndetails.\n\n## License ##\n\nThis project is in the worldwide [public domain](LICENSE).\n\nThis project is in the public domain within the United States, and\ncopyright and related rights in the work worldwide are waived through\nthe [CC0 1.0 Universal public domain\ndedication](https://creativecommons.org/publicdomain/zero/1.0/).\n\nAll contributions to this project will be released under the CC0\ndedication. By submitting a pull request, you are agreeing to comply\nwith this waiver of copyright interest.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcisagov%2Flcgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcisagov%2Flcgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcisagov%2Flcgit/lists"}