{"id":15362300,"url":"https://github.com/gyson/rand_nif","last_synced_at":"2025-04-15T09:14:01.997Z","repository":{"id":57539674,"uuid":"172250700","full_name":"gyson/rand_nif","owner":"gyson","description":"RandNif is a native implementation (NIF) in Rust for random number generator, similar to :rand module.","archived":false,"fork":false,"pushed_at":"2019-03-08T02:37:11.000Z","size":13,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T09:13:48.264Z","etag":null,"topics":["elixir","nif","random-number-generator","rust"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/gyson.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":"2019-02-23T18:45:13.000Z","updated_at":"2021-09-03T16:21:21.000Z","dependencies_parsed_at":"2022-09-26T18:31:49.663Z","dependency_job_id":null,"html_url":"https://github.com/gyson/rand_nif","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/gyson%2Frand_nif","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyson%2Frand_nif/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyson%2Frand_nif/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyson%2Frand_nif/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gyson","download_url":"https://codeload.github.com/gyson/rand_nif/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249040136,"owners_count":21202825,"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","nif","random-number-generator","rust"],"created_at":"2024-10-01T13:00:00.584Z","updated_at":"2025-04-15T09:14:01.977Z","avatar_url":"https://github.com/gyson.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RandNif\n\nRandNif is a native implementation (NIF) in Rust for random number generator, similar to [`:rand`](http://erlang.org/doc/man/rand.html) module.\n\nIt uses Rust's [`rand`](https://github.com/rust-random/rand) library for actual random number generator implementation.\n\nIt uses [`rustler`](https://github.com/hansihe/Rustler) for NIF integration.\n\nNote: this is mostly an **experiment** so far, you may not want to use it in production.\n\n## Installation\n\nThe package can be installed by adding `rand_nif` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:rand_nif, \"~\u003e 0.1.1\"}\n  ]\nend\n```\n\nDocumentation can be found at [https://hexdocs.pm/rand_nif](https://hexdocs.pm/rand_nif).\n\n## Example\n\n```elixir\niex(1)\u003e RandNif.uniform()\n0.37072762226882483\niex(2)\u003e RandNif.uniform(10)\n5\niex(3)\u003e RandNif.uniform(10)\n10\niex(4)\u003e RandNif.uniform(10)\n2\n```\n\n## Analysis\n\n[RandNif: an experiment to speed up random number generator with Rust](https://elixirforum.com/t/randnif-an-experiment-to-speed-up-random-number-generator-with-rust/20395)\n\n## Benchmarks\n\nA simple benchmark scirpt to compare `RandNif` and `:rand` module can be found at `bench/comparison.exs`. Result is as following:\n\n```\nCompiling NIF crate :randnif (native/randnif)...\n    Finished release [optimized] target(s) in 0.06s\nOperating System: macOS\nCPU Information: Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz\nNumber of Available Cores: 8\nAvailable memory: 16 GB\nElixir 1.8.1\nErlang 21.2.4\n\nBenchmark suite executing with the following configuration:\nwarmup: 2 s\ntime: 10 s\nmemory time: 5 s\nparallel: 1\ninputs: none specified\nEstimated total run time: 1.13 min\n\n\nBenchmarking :rand.uniform/0...\nBenchmarking :rand.uniform/1...\nBenchmarking RandNif.uniform/0...\nBenchmarking RandNif.uniform/1...\n\nName                        ips        average  deviation         median         99th %\nRandNif.uniform/0      145.35 K        6.88 μs   ±192.62%        5.96 μs       14.30 μs\nRandNif.uniform/1       71.77 K       13.93 μs    ±38.32%       12.55 μs       22.28 μs\n:rand.uniform/0         44.99 K       22.23 μs    ±42.47%       20.53 μs       42.35 μs\n:rand.uniform/1         37.81 K       26.45 μs    ±34.67%       24.31 μs       43.62 μs\n\nComparison:\nRandNif.uniform/0      145.35 K\nRandNif.uniform/1       71.77 K - 2.03x slower\n:rand.uniform/0         44.99 K - 3.23x slower\n:rand.uniform/1         37.81 K - 3.84x slower\n\nMemory usage statistics:\n\nName                 Memory usage\nRandNif.uniform/0         3.11 KB\nRandNif.uniform/1         1.56 KB - 0.50x memory usage\n:rand.uniform/0          11.97 KB - 3.85x memory usage\n:rand.uniform/1          10.41 KB - 3.35x memory usage\n\n**All measurements for memory usage were the same**\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyson%2Frand_nif","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgyson%2Frand_nif","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyson%2Frand_nif/lists"}