{"id":13561547,"url":"https://github.com/elm/random","last_synced_at":"2025-09-10T20:33:45.986Z","repository":{"id":30282249,"uuid":"124482171","full_name":"elm/random","owner":"elm","description":"Generate random values in Elm","archived":false,"fork":false,"pushed_at":"2024-02-21T09:43:33.000Z","size":47,"stargazers_count":46,"open_issues_count":16,"forks_count":23,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-30T09:41:43.288Z","etag":null,"topics":["elm","generator","random","rng"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/elm/random/latest/","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elm.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":"2018-03-09T03:26:18.000Z","updated_at":"2024-10-31T12:18:43.000Z","dependencies_parsed_at":"2024-01-14T03:30:33.801Z","dependency_job_id":"9199fa00-96aa-420d-945a-7e1d8569277e","html_url":"https://github.com/elm/random","commit_stats":{"total_commits":20,"total_committers":5,"mean_commits":4.0,"dds":"0.19999999999999996","last_synced_commit":"ecf97bb43f0d5cd75243428f69f45323957bda25"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Frandom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Frandom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Frandom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Frandom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elm","download_url":"https://codeload.github.com/elm/random/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237236958,"owners_count":19277082,"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":["elm","generator","random","rng"],"created_at":"2024-08-01T13:00:58.168Z","updated_at":"2025-02-05T03:32:03.245Z","avatar_url":"https://github.com/elm.png","language":"Elm","funding_links":[],"categories":["Elm"],"sub_categories":[],"readme":"# Randomness\n\nNeed to generate random numbers? How about random game boards? Or random positions in 3D space? This is the package for you!\n\n\n## Example\n\nThis package will help you build a random `Generator` like this:\n\n```elm\nimport Random\n\nprobability : Random.Generator Float\nprobability =\n  Random.float 0 1\n\nroll : Random.Generator Int\nroll =\n  Random.int 1 6\n\nusuallyTrue : Random.Generator Bool\nusuallyTrue =\n  Random.weighted (80, True) [ (20, False) ]\n```\n\nIn each of these defines _how_ to generate random values. The most interesting case is `usuallyTrue` which generates `True` 80% of the time and `False` 20% of the time!\n\nNow look at this [working example](https://guide.elm-lang.org/effects/random.html) to see a `Generator` used in an application.\n\n\n## Mindset Shift\n\nIf you are coming from JavaScript, this package is usually quite surprising at first. Why not just call `Math.random()` and get random floats whenever you want? Well, all Elm functions have this “same input, same output” guarantee. That is part of what makes Elm so reliable and easy to test! But if we could generate random values anytime we want, we would have to throw that guarantee out.\n\nSo instead, we create a `Generator` and hand it to the Elm runtime system to do the dirty work of generating values. We get to keep our guarantees _and_ we get random values. Great! And once people become familiar with generators, they often report that it is _easier_ than the traditional imperative APIs for most cases. For example, jump to the docs for [`Random.map4`](Random#map4) for an example of generating random [quadtrees](https://en.wikipedia.org/wiki/Quadtree) and think about what it would look like to do that in JavaScript!\n\nPoint is, this library takes some learning, but we really think it is worth it. So hang in there, and do not hesitate to ask for help on [Slack](https://elmlang.herokuapp.com/) or [Discourse](https://discourse.elm-lang.org/)!\n\n\n## Future Plans\n\nThere are a ton of useful helper functions in the [`elm-community/random-extra`][extra] package. Do you need random `String` values? Random dictionaries? Etc.\n\nWe will probably do an API review and merge the results into this package someday. Not sure when, but it would be kind of nice to have it all in one place. But in the meantime, just do `elm install elm-community/random-extra` if you need stuff from there!\n\n[extra]: https://package.elm-lang.org/packages/elm-community/random-extra/latest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felm%2Frandom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felm%2Frandom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felm%2Frandom/lists"}