{"id":37043624,"url":"https://github.com/s2quake/randora","last_synced_at":"2026-01-14T05:01:08.884Z","repository":{"id":321355940,"uuid":"1085479157","full_name":"s2quake/randora","owner":"s2quake","description":"Lightweight random data generator utilities for .NET. Generate primitives, collections, tuples, enums, text, time values, shuffle, and more—handy for tests, seeding, and demos.","archived":false,"fork":false,"pushed_at":"2025-11-03T05:10:58.000Z","size":246,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-27T12:34:24.337Z","etag":null,"topics":["collections","csharp","dotnet","immutable-collections","library","random","random-data","random-data-generation","shuffle","tuple","xunit"],"latest_commit_sha":null,"homepage":"","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/s2quake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-29T05:07:57.000Z","updated_at":"2025-11-07T08:35:40.000Z","dependencies_parsed_at":"2025-10-29T08:29:04.564Z","dependency_job_id":"f81cc28b-9635-4fbf-9c4c-5e6c18c00366","html_url":"https://github.com/s2quake/randora","commit_stats":null,"previous_names":["s2quake/randora"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/s2quake/randora","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s2quake%2Frandora","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s2quake%2Frandora/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s2quake%2Frandora/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s2quake%2Frandora/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s2quake","download_url":"https://codeload.github.com/s2quake/randora/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s2quake%2Frandora/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28410074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["collections","csharp","dotnet","immutable-collections","library","random","random-data","random-data-generation","shuffle","tuple","xunit"],"created_at":"2026-01-14T05:01:07.908Z","updated_at":"2026-01-14T05:01:08.872Z","avatar_url":"https://github.com/s2quake.png","language":"C#","readme":"# Randora \n\n[![NuGet](https://img.shields.io/nuget/v/JSSoft.Randora.svg?label=release)](https://www.nuget.org/packages/JSSoft.Randora/)\n[![NuGet (prerelease)](https://img.shields.io/nuget/vpre/JSSoft.Randora.svg?label=preview)](https://www.nuget.org/packages/JSSoft.Randora/)\n[![codecov](https://codecov.io/gh/s2quake/randora/branch/main/graph/badge.svg)](https://codecov.io/gh/s2quake/randora)\n[![License](https://img.shields.io/github/license/s2quake/randora.svg)](https://github.com/s2quake/randora/blob/main/LICENSE.md)\n\nA lightweight random-value utility. It provides simple APIs to generate a wide range of data: primitives, collections, enums, text, time values, shuffles, and more.\n\n## Supported frameworks\n\nThis library is packaged as a multi-targeted NuGet.\n\n- .NET 9.0 (default target for development)\n- .NET 8.0\n- .NET 7.0\n- .NET 6.0\n- .NET Standard 2.1\n\n## Quick start: use with an alias\n\nIf `RandomUtility` feels too verbose, define a C# alias for concise code.\n\n```csharp\nusing R = JSSoft.Randora.RandomUtility;\n\n// Now you can call it succinctly:\nint i = R.Int32();\nGuid g = R.Guid();\n```\n\nTo use it project-wide, add a using alias via GlobalUsings or your project file (e.g., Directory.Build.props).\n\n```xml\n\u003cItemGroup\u003e\n  \u003cUsing Include=\"JSSoft.Randora.RandomUtility\" Alias=\"R\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\n## Basic usage\n\n### Primitives\n\n```csharp\nusing R = JSSoft.Randora.RandomUtility;\n\n// Using the default (shared) Random\nint i = R.Int32();                    // arbitrary int\nint iInRange = R.Int32(-10, 10);      // [-10, 9]\nlong l = R.Int64();                   // arbitrary long\ndouble d = R.Double();                // double in [0.0, 1.0)\ndecimal m = R.Decimal();              // decimal in [0m, 1m)\nbool b = R.Boolean();                 // true/false\nGuid g = R.Guid();                    // random Guid\nstring hex = R.Hex(8);                // 8 bytes → 16 hex characters\nstring word = R.Word();               // a single word\nstring sentence = R.String();         // 1–9 words joined by spaces\n\n// Date/Time\nDateTimeOffset dto = R.DateTimeOffset(); // roughly UnixEpoch ~ 2050-12-31\nTimeSpan ts = R.TimeSpan();              // 0 to less than 365 days\nTimeSpan tsMs = R.TimeSpan(10, 20);      // 10ms ~ 19ms\n\n// BigInteger and sign helpers\nBigInteger bi = R.BigInteger();          // internally based on 1–16 random bytes\nint pos = R.Positive();                  // \u003e 0\nint nonNeg = R.NonNegative();            // \u003e= 0\n```\n\nEvery API also has an overload that accepts a `Random` instance. For reproducible outcomes, pass a seeded `Random`.\n\n```csharp\nvar r = new Random(1234);\nint v = R.Int32(r, -100, 100);\nGuid gid = R.Guid(r);\n```\n\n### Collections\n\nProvide only a generator delegate and get back many types of collections. If you omit the length, `R.Length()` (defaults to 1–9) is used internally.\n\n```csharp\n// Arrays/Lists\nint[] arr = R.Array(R.Int32, length: 5);\nList\u003cstring\u003e list = R.List(R.String, length: 3);\n\n// Sets (attempt to ensure uniqueness), sorted sets/dictionaries\nHashSet\u003cint\u003e set = R.HashSet(R.Int32, length: 10);\nSortedSet\u003cint\u003e sortedSet = R.SortedSet(R.Int32, length: 10);\n\n// Dictionaries (keys must be unique)\nvar dict = R.Dictionary(() =\u003e R.Int32(0, 10_000), R.String, length: 20);\nvar sortedDict = R.SortedDictionary(() =\u003e R.Int32(0, 10_000), R.String, length: 20);\n\n// Immutable collections\nvar ia = R.ImmutableArray(R.Int32, length: 4);\nvar il = R.ImmutableList(R.Int32, length: 6);\nvar ihs = R.ImmutableHashSet(R.Int32, length: 10);\nvar iss = R.ImmutableSortedSet(R.Int32, length: 10);\nvar id = R.ImmutableDictionary(() =\u003e R.Int32(0, 10_000), R.String, length: 10);\nvar isd = R.ImmutableSortedDictionary(() =\u003e R.Int32(0, 10_000), R.String, length: 10);\n\n// With an explicit Random (useful for reproducible tests)\nvar r = new Random(7);\nint[] seeded = R.Array(r, rr =\u003e R.Int32(rr, 0, 100), length: 5);\n```\n\n### Tuples and value tuples\n\nGenerate System.Tuple and C# value tuples by providing element generators. Two-element examples shown here; higher arities are also available.\n\n```csharp\nusing R = JSSoft.Randora.RandomUtility;\n\n// System.Tuple\u003cT1, T2\u003e\nTuple\u003cint, string\u003e t = R.Tuple(R.Int32, R.String);\n\n// With an explicit Random (for reproducibility)\nvar r = new Random(123);\nTuple\u003cint, string\u003e tSeeded = R.Tuple(r, rr =\u003e R.Int32(rr, 0, 100), R.String);\n\n// ValueTuple\u003cT1, T2\u003e\n(int n, string s) vt = R.ValueTuple(R.Int32, R.String);\n\n// Seeded value tuple\nvar r2 = new Random(123);\nvar vtSeeded = R.ValueTuple(r2, rr =\u003e R.Int32(rr, 0, 100), R.String);\n```\n\n### Nullable and NullableObject\n\nProduce nullable value types via the `Nullable*` helpers (or the generic `Nullable\u003cT\u003e`), and nullable reference types via `NullableObject*` (or the generic `NullableObject\u003cT\u003e`). By default, there is a 66% chance of a non-null value.\n\n```csharp\nusing R = JSSoft.Randora.RandomUtility;\n\n// Value type (int?)\nint? maybeInt = R.NullableInt32();                // ~66% non-null\nint? maybeInt2 = R.Nullable(R.Int32);             // same behavior via generic helper\n\n// Reference type (string?)\nstring? maybeString = R.NullableString();         // ~66% non-null\nstring? maybeString2 = R.NullableObject(R.String);\n\n// Seeded variants\nvar r = new Random(2025);\nint? seededInt = R.NullableInt32(r);\nstring? seededString = R.NullableString(r);\n```\n\n### Try, Chance, Random, RandomOrDefault\n\n```csharp\n// Try: generate until a predicate is satisfied → throws MaxAttemptsExceededException\n// if the generator keeps failing to meet the predicate repeatedly\nint even = R.Try(() =\u003e R.Int32(0, 10), x =\u003e x % 2 == 0);\n\n// Chance: return true/false with a probability\nbool p30 = R.Chance(30);     // 30%\nbool pHalf = R.Chance(0.5);  // 50%\n\n// Enumerable extensions: pick a random element\nvar nums = new[] { 1, 2, 3 };\nint pick = nums.Random();                 // throws InvalidOperationException if empty\nint pickOrDefault = nums.RandomOrDefault(); // returns default(int) == 0 if empty\n\n// For classes/nullables\nobject? o = Array.Empty\u003cobject\u003e().RandomOrDefault(); // returns null\n```\n\n### Length utility\n\n```csharp\nint any = R.Length();        // 1 ~ 9\nint l1to6 = R.Length(7);     // 1 ~ 6 (exclusive upper bound)\nint l3to6 = R.Length(3, 7);  // 3 ~ 6 (exclusive upper bound)\n```\n\n## Notes\n\n- `Enum\u003cT\u003e()` does not support [Flags] enums and throws `InvalidOperationException`.\n- The `Random()` / `RandomOrDefault()` extensions operate on `IEnumerable\u003cT\u003e`. `Random()` throws on empty sequences; `RandomOrDefault()` returns `default(T)`.\n- When length is omitted for collection generators, the internal `R.Length()` result is used (defaults to 1–9). If key/value collisions occur repeatedly, you may end up with fewer items than requested.\n\n```csharp\n// Library namespace\n// using JSSoft.Randora; // (RandomUtility resides in this namespace)\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs2quake%2Frandora","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs2quake%2Frandora","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs2quake%2Frandora/lists"}