{"id":13594961,"url":"https://github.com/smol-rs/fastrand","last_synced_at":"2025-05-13T22:05:24.834Z","repository":{"id":40318152,"uuid":"267368764","full_name":"smol-rs/fastrand","owner":"smol-rs","description":"A simple and fast random number generator","archived":false,"fork":false,"pushed_at":"2025-02-03T08:16:33.000Z","size":117,"stargazers_count":483,"open_issues_count":9,"forks_count":38,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-22T09:53:59.714Z","etag":null,"topics":["rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smol-rs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2020-05-27T16:19:19.000Z","updated_at":"2025-04-21T19:37:12.000Z","dependencies_parsed_at":"2024-04-27T20:26:34.652Z","dependency_job_id":"2aa72cbe-a644-4319-9459-c1cceaa7b61e","html_url":"https://github.com/smol-rs/fastrand","commit_stats":{"total_commits":114,"total_committers":17,"mean_commits":6.705882352941177,"dds":0.6578947368421053,"last_synced_commit":"1b93479b8ea275997771df15aa4dbd54ee01bd6d"},"previous_names":["stjepang/fastrand"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Ffastrand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Ffastrand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Ffastrand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Ffastrand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smol-rs","download_url":"https://codeload.github.com/smol-rs/fastrand/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251340712,"owners_count":21573968,"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":["rust"],"created_at":"2024-08-01T16:01:41.554Z","updated_at":"2025-04-28T15:42:07.276Z","avatar_url":"https://github.com/smol-rs.png","language":"Rust","funding_links":[],"categories":["Rust","Libraries"],"sub_categories":[],"readme":"# fastrand\n\n[![Build](https://github.com/smol-rs/fastrand/workflows/CI/badge.svg)](\nhttps://github.com/smol-rs/fastrand/actions)\n[![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](\nhttps://github.com/smol-rs/fastrand)\n[![Cargo](https://img.shields.io/crates/v/fastrand.svg)](\nhttps://crates.io/crates/fastrand)\n[![Documentation](https://docs.rs/fastrand/badge.svg)](\nhttps://docs.rs/fastrand)\n\nA simple and fast random number generator.\n\nThe implementation uses [Wyrand](https://github.com/wangyi-fudan/wyhash), a simple and fast\ngenerator but **not** cryptographically secure.\n\n## Examples\n\nFlip a coin:\n\n```rust\nif fastrand::bool() {\n    println!(\"heads\");\n} else {\n    println!(\"tails\");\n}\n```\n\nGenerate a random `i32`:\n\n```rust\nlet num = fastrand::i32(..);\n```\n\nChoose a random element in an array:\n\n```rust\nlet v = vec![1, 2, 3, 4, 5];\nlet i = fastrand::usize(..v.len());\nlet elem = v[i];\n```\n\nSample values from an array with `O(n)` complexity (`n` is the length of array):\n\n```rust\nfastrand::choose_multiple([1, 4, 5], 2);\nfastrand::choose_multiple(0..20, 12);\n```\n\nShuffle an array:\n\n```rust\nlet mut v = vec![1, 2, 3, 4, 5];\nfastrand::shuffle(\u0026mut v);\n```\n\nGenerate a random `Vec` or `String`:\n\n```rust\nuse std::iter::repeat_with;\n\nlet v: Vec\u003ci32\u003e = repeat_with(|| fastrand::i32(..)).take(10).collect();\nlet s: String = repeat_with(fastrand::alphanumeric).take(10).collect();\n```\n\nTo get reproducible results on every run, initialize the generator with a seed:\n\n```rust\n// Pick an arbitrary number as seed.\nfastrand::seed(7);\n\n// Now this prints the same number on every run:\nprintln!(\"{}\", fastrand::u32(..));\n```\n\nTo be more efficient, create a new `Rng` instance instead of using the thread-local\ngenerator:\n\n```rust\nuse std::iter::repeat_with;\n\nlet rng = fastrand::Rng::new();\nlet mut bytes: Vec\u003cu8\u003e = repeat_with(|| rng.u8(..)).take(10_000).collect();\n```\n\nThis crate aims to expose a core set of useful randomness primitives. For more niche algorithms, consider using the [`fastrand-contrib`] crate alongside this one.\n\n# Features\n\n- `std` (enabled by default): Enables the `std` library. This is required for the global\n  generator and global entropy. Without this feature, [`Rng`] can only be instantiated using\n  the [`with_seed`](https://docs.rs/fastrand/latest/fastrand/struct.Rng.html#method.with_seed) method.\n- `js`: Assumes that WebAssembly targets are being run in a JavaScript environment.\n\n[`fastrand-contrib`]: https://crates.io/crates/fastrand-contrib\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n#### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmol-rs%2Ffastrand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmol-rs%2Ffastrand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmol-rs%2Ffastrand/lists"}