{"id":20619030,"url":"https://github.com/tessapower/my-pseudo-rand","last_synced_at":"2026-04-25T03:37:00.591Z","repository":{"id":188839762,"uuid":"381926417","full_name":"tessapower/my-pseudo-rand","owner":"tessapower","description":"Repo for a lightning talk I gave on Pseudo Random Number Generators (LCG Algorithm).","archived":false,"fork":false,"pushed_at":"2025-09-29T11:46:51.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-29T13:28:33.266Z","etag":null,"topics":["presentation","pseudo-random-generator","randomized-testing","talk","testing"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tessapower.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-07-01T06:00:59.000Z","updated_at":"2025-09-29T11:46:55.000Z","dependencies_parsed_at":"2023-08-17T05:12:04.562Z","dependency_job_id":null,"html_url":"https://github.com/tessapower/my-pseudo-rand","commit_stats":null,"previous_names":["tessapower/my-pseudo-rand"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tessapower/my-pseudo-rand","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tessapower%2Fmy-pseudo-rand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tessapower%2Fmy-pseudo-rand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tessapower%2Fmy-pseudo-rand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tessapower%2Fmy-pseudo-rand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tessapower","download_url":"https://codeload.github.com/tessapower/my-pseudo-rand/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tessapower%2Fmy-pseudo-rand/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32249297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T03:17:44.950Z","status":"ssl_error","status_checked_at":"2026-04-25T03:16:45.208Z","response_time":59,"last_error":"SSL_read: 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":["presentation","pseudo-random-generator","randomized-testing","talk","testing"],"created_at":"2024-11-16T12:10:15.673Z","updated_at":"2026-04-25T03:37:00.552Z","avatar_url":"https://github.com/tessapower.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Pseudo-Random Number Generator\n\nRepo for a lightning talk I gave on Pseudo-Random Number Generators (with practical examples based on the LCG algorithm).\n\nSee also: [tessapower/seeded_random_tests](https://github.com/tessapower/seeded_random_tests).\n\nThis generator produces a sequence of pseudo-random numbers in the range [0, 1)—between 0 and 1 (not including 1).\n\n### Organised Chaos\n\nThe numbers generated are pseudo-random because the generator will produce the same sequence of numbers given the same\nstarting (seed) value. To a human, however, we are not able to reasonably predict the next number in the sequence, so\nthey appear to be random.\n\nWith this algorithm, and given any term of the sequence, we can always calculate the next term of the sequence.\nImportantly, these properties mean that the PRNG is *deterministic*.\n\n### Algorithm\n\nThere are many algorithms that can be used to generate a random number. A fairly simple one is the \n[Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_congruential_generator#Sample_code)\n(LCG) algorithm, which this generator uses.\n\n#### Definition\n\nThe LCG algorithm is defined by the recurrence relation:\n\n\u003cimg alt=\"LCG Recurrence Relation\" src=\"./assets/lcg-recurrence-relation.svg\" height=30 /\u003e\n\nwhere:\n\n\u003cimg alt=\"Modulus\" src=\"./assets/m.svg\" height=30 /\u003e — The \"Modulus\"\u003cbr\u003e\n\u003cimg alt=\"Multiplier\" src=\"./assets/a.svg\" height=30 /\u003e — The \"Multiplier\"\u003cbr\u003e\n\u003cimg alt=\"Increment\" src=\"./assets/c.svg\" height=30 /\u003e — The \"Increment\"\u003cbr\u003e\n\u003cimg alt=\"Seed or Starting Value\" src=\"./assets/X_0.svg\" height=30 /\u003e — The \"Seed\"\u003cbr\u003e\n\n#### Modulus\n\nThe Modulus provides the upper bound of the random number generated, so the possible range is limited to any number\nbetween 0 and the Modulus - 1. In this case, we use the Modulus to create a large range of numbers so that the next\nnumber in the sequence is not (easily) predictable.\n\n#### Multiplier and Increment\n\nThe Multiplier and Increment introduce \"chaos\" into the calculation that helps to make the output *appear* random to\nmere mortals.\n\n#### Seed\n\nThe Seed `X_0` replaces `X_n` in the recurrence relation equation to calculate the first number in the sequence, which\nall following numbers extend from.\n\n#### Chosen Values\n\nThe values of the Modulus, Multiplier, and Increment can be arbitrary. However, there are certain tried and tested\nvalues which are more effective than the ones we can think of off the top of our heads. This generator uses:\n\n| Source | Modulus (m) | Multiplier (a) | Increment (c) |\n|:------:|:-----------:|:--------------:|:-------------:|\n| [Numerical Recipes](http://numerical.recipes/) | `2^32` | `1664525` | `1013904223` |\n\nIf a seed isn't supplied, we convert a hash created from the current time into a number. Using an arbitrary hardcoded\nvalue by default will mean the first value in the sequence is the same each time—using a value that constantly changes,\ni.e. the current time, will appear more random.\n\nUsing the time alone, however, will mean that two objects instantiated around the same time will have similar seeds, and\nthe first number in their sequences will also appear similar. For this reason, we use a hash to ensure the seed is\ncompletely different, given a small change in the value of the seed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftessapower%2Fmy-pseudo-rand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftessapower%2Fmy-pseudo-rand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftessapower%2Fmy-pseudo-rand/lists"}