{"id":26777275,"url":"https://github.com/timothymeadows/securerandom.netcore","last_synced_at":"2026-02-24T02:18:07.073Z","repository":{"id":96219783,"uuid":"282897116","full_name":"TimothyMeadows/SecureRandom.NetCore","owner":"TimothyMeadows","description":"Cryptographic pseudorandom number generator (CPRNG) using Blake2b, and PinnedMemory.","archived":false,"fork":false,"pushed_at":"2020-08-29T15:30:09.000Z","size":15,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-18T00:53:50.594Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/TimothyMeadows.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,"zenodo":null}},"created_at":"2020-07-27T12:51:19.000Z","updated_at":"2021-10-09T01:08:21.000Z","dependencies_parsed_at":"2023-04-27T14:47:23.753Z","dependency_job_id":null,"html_url":"https://github.com/TimothyMeadows/SecureRandom.NetCore","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/TimothyMeadows/SecureRandom.NetCore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FSecureRandom.NetCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FSecureRandom.NetCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FSecureRandom.NetCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FSecureRandom.NetCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimothyMeadows","download_url":"https://codeload.github.com/TimothyMeadows/SecureRandom.NetCore/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FSecureRandom.NetCore/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262018759,"owners_count":23245619,"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-03-29T04:49:22.590Z","updated_at":"2026-02-24T02:18:07.067Z","avatar_url":"https://github.com/TimothyMeadows.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SecureRandom.NetCore\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![NuGet](https://img.shields.io/nuget/v/SecureRandom.NetCore.svg)](https://www.nuget.org/packages/SecureRandom.NetCore/)\n\n`SecureRandom.NetCore` is a cryptographic pseudo-random number generator (CPRNG) for .NET, based on [Blake2b.NetCore](https://github.com/TimothyMeadows/Blake2b.NetCore) and optimized to reduce memory exposure through [PinnedMemory](https://github.com/TimothyMeadows/PinnedMemory).\n\n## Table of contents\n\n- [Runtime support](#runtime-support)\n- [Installation](#installation)\n- [Quick start](#quick-start)\n- [Security notes](#security-notes)\n- [API reference](#api-reference)\n- [Examples project](#examples-project)\n- [Testing](#testing)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Runtime support\n\n- .NET 8 (`net8.0`)\n\n## Installation\n\n### .NET CLI\n\n```bash\ndotnet add package SecureRandom.NetCore\n```\n\n### Package Manager Console\n\n```powershell\nInstall-Package SecureRandom.NetCore\n```\n\n### NuGet\n\nhttps://www.nuget.org/packages/SecureRandom.NetCore/\n\n## Quick start\n\n```csharp\nusing SecureRandom.NetCore;\n\nusing var cprng = new SecureRandom();\n\n// Generate a new byte array\nbyte[] token = cprng.NextBytes(32);\n\n// Fill an existing buffer\nbyte[] nonce = new byte[12];\ncprng.NextBytes(nonce);\n\n// Random primitives\nint count = cprng.Next(1, 100);\nlong id = cprng.NextLong();\ndouble value = cprng.NextDouble();\n```\n\n## Security notes\n\n- By default, the constructor auto-seeds from the OS entropy provider (`RandomNumberGenerator.Fill`).\n- Avoid `seed: false` unless you explicitly provide secure seed material via `SetSeed(...)` before calling generation APIs.\n- `SecureRandom` implements `IDisposable`; always dispose instances to clear and release internal state.\n\n## API reference\n\n### Constructor\n\n```csharp\nSecureRandom(int rounds = 10, bool seed = true)\n```\n\n- `rounds`: Number of state generations before cycling seed material.\n- `seed`: When `true` (default), instance self-seeds with OS entropy.\n\n\u003e ⚠️ `seed: false` creates an unseeded generator. Calling random generation methods before `SetSeed(...)` will throw.\n\n### Methods\n\n| Method | Description |\n| --- | --- |\n| `int GetSeedSize()` | Gets digest output length used for internal state and seed buffers. |\n| `void SetSeed(byte[] seed)` | Mixes user-provided byte seed material into internal seed state. |\n| `void SetSeed(long seed)` | Mixes user-provided integral seed material into internal seed state. |\n| `int Next()` | Returns a non-negative random `int`. |\n| `int Next(int maxValue)` | Returns random `int` in `[0, maxValue)`. |\n| `int Next(int minValue, int maxValue)` | Returns random `int` in `[minValue, maxValue)`. |\n| `byte[] NextBytes(int length)` | Creates and returns a random byte array of `length`. |\n| `void NextBytes(byte[] bytes)` | Fills provided byte array with random data. |\n| `void NextBytes(byte[] bytes, int offset, int length)` | Fills a segment of a byte array with random data. |\n| `double NextDouble()` | Returns random `double` in range `[0, 1]`. |\n| `int NextInt()` | Returns random `int` over full signed 32-bit range. |\n| `long NextLong()` | Returns random `long` over full signed 64-bit range. |\n| `void Dispose()` | Disposes digest/state resources and suppresses finalization. |\n\n## Examples project\n\nSample usage is available in:\n\n- `SecureRandom.NetCore.Examples/Program.cs`\n\nRun it with:\n\n```bash\ndotnet run --project SecureRandom.NetCore.Examples\n```\n\n## Testing\n\nThis repository includes unit tests in `SecureRandom.NetCore.Tests`.\n\nRun all tests:\n\n```bash\ndotnet test SecureRandom.NetCore.sln\n```\n\n## Contributing\n\nIssues and pull requests are welcome.\n\n1. Fork the repository.\n2. Create a feature branch.\n3. Add or update tests.\n4. Run `dotnet test`.\n5. Open a pull request with a clear summary.\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothymeadows%2Fsecurerandom.netcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimothymeadows%2Fsecurerandom.netcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothymeadows%2Fsecurerandom.netcore/lists"}