{"id":20072221,"url":"https://github.com/wilwade/rand_pcg","last_synced_at":"2025-10-25T22:40:14.757Z","repository":{"id":57539742,"uuid":"97023392","full_name":"wilwade/rand_pcg","owner":"wilwade","description":"Elixir Random Number Generator based on PCG","archived":false,"fork":false,"pushed_at":"2017-07-12T21:20:57.000Z","size":62,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-18T00:51:13.163Z","etag":null,"topics":["elixir"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wilwade.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}},"created_at":"2017-07-12T15:25:24.000Z","updated_at":"2024-04-02T15:16:53.000Z","dependencies_parsed_at":"2022-09-26T18:31:51.528Z","dependency_job_id":null,"html_url":"https://github.com/wilwade/rand_pcg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilwade%2Frand_pcg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilwade%2Frand_pcg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilwade%2Frand_pcg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilwade%2Frand_pcg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wilwade","download_url":"https://codeload.github.com/wilwade/rand_pcg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224468186,"owners_count":17316325,"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":["elixir"],"created_at":"2024-11-13T14:39:00.250Z","updated_at":"2025-10-25T22:40:14.673Z","avatar_url":"https://github.com/wilwade.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RandPCG\n\nA random number generator using the [PCG](http://www.pcg-random.org/) algorithm.\n\nDocumentation: https://hexdocs.pm/rand_pcg/\n\n## Installation\n\n  1. Add `rand_pcg` to your list of dependencies in `mix.exs`:\n\n    ```elixir\n    def deps do\n      [{:rand_pcg, \"~\u003e 0.1.2\"}]\n    end\n    ```\n\n  2. If you are using the GenServer option, ensure `rand_pcg` is started before\n   your application:\n\n    ```elixir\n    def application do\n      [applications: [:rand_pcg]]\n    end\n    ```\n\n## Examples\n\n### GenServer Option\n\n#### Get Some Random\n\n```elixir\n# Random 32 bit integer\nRandPCG.random()\n\n# Random 32 bit based float\nRandPCG.random(:float)\n\n# n Random 32 bit integers\nRandPCG.random(n)\n\n# Random nth of an enumerable\nlist = [:a, :b, :c]\nRandPCG.random(list)\n\n# Random integer x where min \u003c= x \u003c= max\nRandPCG.random(min, max)\n\n# n random integers x where min \u003c= x \u003c= max\nRandPCG.random(min, max, n)\n```\n\n#### Set State\n\n```elixir\nstate = %RandPCG.State{seed: 234532454323451, inc: 1}\nRandPCG.state(state)\n```\n\n#### Note\n\nThe initial seed is based on `:os.system_time(:micro_seconds)`\n\n### Without running the GenServer\n\nYou will have to maintain your own state of the random number generator.\n\n#### Random 32 bit Integer\n\n```elixir\nstate = RandPCG.PCG.gen_state()\nrandom_int_32 = RandPCG.PCG.xsh_rr(state)\nstate = advance(state)\n```\n\nIf you do not advance the state, you will receive the same random number.\n\n#### Random Integer in a Range\n\n```elixir\nstate = RandPCG.PCG.gen_state()\nmin = 1\nmax = 10\nrandom_1_10_inclusive = RandPCG.PCG.rand_int(min, max, state)\nstate = advance(state)\n```\n\n`RandPCG.PCG.gen_state` initial seed is based on `:os.system_time(:micro_seconds)`\n\n## References\n\n- [PCG Random Number Generator Homepage](http://www.pcg-random.org/)\n- [PCG Basic C Implementation](https://github.com/imneme/pcg-c-basic)\n- [PCG Go Implementation](https://github.com/dgryski/go-pcgr) was also helpful\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilwade%2Frand_pcg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilwade%2Frand_pcg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilwade%2Frand_pcg/lists"}