{"id":15047503,"url":"https://github.com/tbxfreeware/seed_randomly","last_synced_at":"2026-02-07T19:33:33.349Z","repository":{"id":183104390,"uuid":"669606892","full_name":"tbxfreeware/seed_randomly","owner":"tbxfreeware","description":"Seed a C++ random number engine with random seeds from std:random_device. Works with any engine that can be seeded with a seed sequence, including those in the C++ Standard Library.","archived":false,"fork":false,"pushed_at":"2023-11-10T19:40:23.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-12T03:50:35.120Z","etag":null,"topics":["cpp14","cpp14-library","mt19937","random-number-generators","seeder"],"latest_commit_sha":null,"homepage":"","language":"C++","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/tbxfreeware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-22T20:40:21.000Z","updated_at":"2023-07-23T15:29:02.000Z","dependencies_parsed_at":"2025-03-14T03:31:26.374Z","dependency_job_id":null,"html_url":"https://github.com/tbxfreeware/seed_randomly","commit_stats":null,"previous_names":["tbxfreeware/seed_randomly"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tbxfreeware/seed_randomly","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbxfreeware%2Fseed_randomly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbxfreeware%2Fseed_randomly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbxfreeware%2Fseed_randomly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbxfreeware%2Fseed_randomly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbxfreeware","download_url":"https://codeload.github.com/tbxfreeware/seed_randomly/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbxfreeware%2Fseed_randomly/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29205259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T17:44:10.191Z","status":"ssl_error","status_checked_at":"2026-02-07T17:44:07.936Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cpp14","cpp14-library","mt19937","random-number-generators","seeder"],"created_at":"2024-09-24T20:59:20.923Z","updated_at":"2026-02-07T19:33:33.331Z","avatar_url":"https://github.com/tbxfreeware.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# seed_randomly\nHeader `tbx.cpp14.seed_randomly.h` is a single-file \"library\" that provides tools for seeding a C++ random number engine. It works with any engine that can be seeded with a seed sequence, including all of the random number engines in the C++ Standard Library. It generates seeds using `std:random_device`.\n\nThis header uses only the features of C++14, nothing later.\n\n\u0026nbsp;\n## A good choice for `mt19937`\nThe tools here are particularly useful for seeding `std::mt19937` and `std::19937_64`. Those engines have 19,968 bits of state, so trying to seed them with a single seed of only 32 or 64 bits is borderline foolish. The functions in this header supply a full 19,968 bits.\n\nUsing one of the methods described in the following two sections is far superior to seeding with something like `std::time(nullptr)` or `std::chrono::high_resolution_clock::now().time_since_epoch().count()`, which, respectively, have only 32 and 64 bits of entropy.\n\n\u0026nbsp;\n## seed_randomly\nThis function takes a random number engine as argument, and seeds it with random seeds generated from `std::random_device`.\n````cpp\n// Example: Seed `mt19937`.\nstd::mt19937 mt;\ntbx::seed_randomly( mt );\n\n// Example: Seed `pcg32`, one of the PCG engines by Melissa O'Neill.\npcg32 e;\ntbx::seed_randomly( e );\n````\n\n\u0026nbsp;\n## class seed_seq_rd\nThis class mimics the interface of `std::seed_seq`, but uses `std::random_device` to generate seeds. Objects of this type are seed sequences that can be used as arguments to member function `seed` in a random number engine.\n\nA `seed_seq_rd` object can also be used as an argument to the constructor of a random number engine, and anywhere else that a `std:seed_seq` object can be used.\n\nFunction `seed_randomly` is a trivial wrapper around a `seed_seq_rd` object.\n````cpp\n// Example: Seed `mt19937` with random seeds from `std::random_device`.\ntbx::seed_seq_rd s;\nstd::mt19937 mt{ s };\n\n// Example: Seed `mt19937_64` with random seeds from `std::random_device`.\ntbx::seed_seq_rd s;\nstd::mt19937_64 mt64;\nmt64.seed( s );\n\n// Example: Seed `pcg32`, one of the PCG engines by Melissa O'Neill.\npcg32 e;\ne.seed( s );  // `seed_seq_rd` object can be reused.\n\n// Example: Implementation of `seed_randomly`:\ntemplate\u003c typename RandomNumberEngine \u003e\nvoid seed_randomly( RandomNumberEngine\u0026 e );\n{\n    tbx::seed_seq_rd s;\n    e.seed( s );\n}\n````\n\n\u0026nbsp;\n## Check `random_device`\nBefore using this library, you should satisfy yourself that `std::random_device` is a good source of entropy on your system. Sometimes, it is not.\n\n[Microsoft Visual C++](https://learn.microsoft.com/en-us/cpp/standard-library/random-device-class?view=msvc-170), for instance, generates \"non-deterministic and cryptographically secure\" values, and never blocks, which is excellent. Prior to version 9.2, however, [MinGW distributions of GCC](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85494) used `std::mt19937` with a fixed seed! Those systems generated the same sequence every time. (Newer versions purport to have fixed the problem, but I have not checked.) [Unix-like systems](https://en.wikipedia.org/wiki//dev/random) often use `/dev/random` (which can block) or `/dev/urandom`. Both have their advantages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbxfreeware%2Fseed_randomly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbxfreeware%2Fseed_randomly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbxfreeware%2Fseed_randomly/lists"}