{"id":27305378,"url":"https://github.com/krtab/rand-array-iid","last_synced_at":"2025-04-12T03:28:36.959Z","repository":{"id":62443556,"uuid":"301486317","full_name":"krtab/rand-array-iid","owner":"krtab","description":"A rust crate to create arrays whose elements are independently identically distributed.","archived":false,"fork":false,"pushed_at":"2020-10-14T21:01:26.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T05:52:31.323Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/krtab.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-05T17:23:28.000Z","updated_at":"2020-10-14T21:01:28.000Z","dependencies_parsed_at":"2022-11-01T22:16:24.098Z","dependency_job_id":null,"html_url":"https://github.com/krtab/rand-array-iid","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Frand-array-iid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Frand-array-iid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Frand-array-iid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krtab%2Frand-array-iid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krtab","download_url":"https://codeload.github.com/krtab/rand-array-iid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248511781,"owners_count":21116464,"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":[],"created_at":"2025-04-12T03:28:36.316Z","updated_at":"2025-04-12T03:28:36.943Z","avatar_url":"https://github.com/krtab.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rand-array-iid\n\n[![Build Status](https://img.shields.io/travis/krtab/rand-array-iid/main?style=flat-square)](https://travis-ci.org/krtab/rand-array-iid)\n[![Crates.io](https://img.shields.io/crates/v/rand-array-iid?style=flat-square)](https://crates.io/crates/rand-array-iid)\n[![Docs](https://img.shields.io/badge/docs-doc.rs-blue?style=flat-square)](https://docs.rs/rand-array-iid/)\n\nA rust crate to create arrays whose elements are independently identically distributed.\n\n## Install\n\n```\n[dependencies]\nrand-array-iid = \"0.1.0\"\n```\n\n## Examples\n\n### An array of normally distributed scalars\n```rust\nuse rand_array_iid::IIDDistr;\nuse rand_distr::Distribution;\nuse rand_distr::StandardNormal;\nlet distr = IIDDistr::new(StandardNormal);\nlet mut rng = rand::thread_rng();\n// Each of x element is distributed according to StandardNormal.\nlet x : [f64; 10] = distr.sample(\u0026mut rng);\n```\n\n### An array of 3D vectors sampled from the unit sphere\n```rust\nuse rand_array_iid::IIDDistr;\nuse rand_distr::Distribution;\nuse rand_distr::UnitSphere;\nlet distr = IIDDistr::new(UnitSphere);\nlet mut rng = rand::thread_rng();\n// Each of x element is sampled uniformly from the surface of the 3D unit sphere.\nlet x : [[f64; 3]; 10] = distr.sample(\u0026mut rng);\n```\n\n## Why only arrays?\n\nCollections such as `Vec` that implement `std::iter::FromIterator` bear\nno information on their size in their type, hence the distribution would have\nto be restricted to a given size. They can also be sampled as follow:\n\n```rust\nuse rand_distr::Distribution;\nuse rand::Rng;\nfn sample_iid\u003cD,R, Col\u003e(dist: D, rng: \u0026mut R, n: usize) -\u003e Col\nwhere\n    R: Rng + ?Sized,\n    Col: std::iter::IntoIterator,\n    Col: std::iter::FromIterator\u003c\u003cCol as std::iter::IntoIterator\u003e::Item\u003e,\n    D: Distribution\u003c\u003cCol as std::iter::IntoIterator\u003e::Item\u003e,\n{\n    dist.sample_iter(rng).take(n).collect()\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrtab%2Frand-array-iid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrtab%2Frand-array-iid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrtab%2Frand-array-iid/lists"}