{"id":22729330,"url":"https://github.com/ahotko/mathextended","last_synced_at":"2025-03-30T00:44:13.944Z","repository":{"id":178928951,"uuid":"280096840","full_name":"ahotko/MathExtended","owner":"ahotko","description":"C# Math Library with Functions, not included in standard Library. Compatible with NET.Core and NET.Framework","archived":false,"fork":false,"pushed_at":"2024-02-26T14:59:46.000Z","size":346,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-05T02:51:52.759Z","etag":null,"topics":["continued-fractions","csharp","csharp-code","csharp-library","easing","easing-functions","easings","fractions","histogram","interpolation","matrix","netcore","random","ranmar","standard-deviation","statistics"],"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/ahotko.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}},"created_at":"2020-07-16T08:23:47.000Z","updated_at":"2023-04-12T09:08:10.000Z","dependencies_parsed_at":"2024-02-26T16:08:38.323Z","dependency_job_id":null,"html_url":"https://github.com/ahotko/MathExtended","commit_stats":null,"previous_names":["ahotko/mathextended"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahotko%2FMathExtended","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahotko%2FMathExtended/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahotko%2FMathExtended/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahotko%2FMathExtended/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahotko","download_url":"https://codeload.github.com/ahotko/MathExtended/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246262491,"owners_count":20749171,"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":["continued-fractions","csharp","csharp-code","csharp-library","easing","easing-functions","easings","fractions","histogram","interpolation","matrix","netcore","random","ranmar","standard-deviation","statistics"],"created_at":"2024-12-10T18:09:34.439Z","updated_at":"2025-03-30T00:44:13.926Z","avatar_url":"https://github.com/ahotko.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MathExtended\n\nPure C# MathLibrary.\n\n# Legal information and credits\n\nMathExtended is project by Ales Hotko and was first released in 2020. It's licensed under the MIT license.\n\n------\n\n[TOC]\n\n------\n\n\n\n# Libraries\n\n## Common\n\n[Common](doc/MathExtended.Common.md)\n\n\n\n## Complex Numbers\n\n\n\n## Matrices\n\n### Creating\n\n#### Square Matrix\n```csharp\n//Create square matrix of size 3x3\nMatrix matrix = new Matrix(3);\n```\n#### Matrix of any size\n```csharp\n//Create matrix of any size (i.e. 5x3)\nMatrix matrix = new Matrix(5, 3);\n```\n#### Zero Matrix\n```csharp\nMatrix zero = Matrix.Zero(rows, cols);\n//..or..\nMatrix zeroSquare = Matrix.Zero(size);\n```\n##### Identity Matrix\n```csharp\nMatrix identity = Matrix.Identity(size);\n```\n### Populating the matrix\n```csharp\n//Populate Matrix\nmatrix[1, 1] = 5.0;\nmatrix[1, 2] = 5.0;\nmatrix[1, 3] = 5.0;\n//...or populate with random values between -5.0 and 10.0\nmatrix.Randomize(-5,0, 10.0);\n//..or with random values between 0 and 1\nmatrix.Randomize();\n```\n### Math operations\n```csharp\nMatrix a = new Matrix(3, 3);\nMatrix b = new Matrix(3, 3);\n```\n#### Addition\n```csharp\nMatrix sum = a + b;\n//..or..\na.Add(b);\n```\n#### Subtraction\n```csharp\nMatrix diff = a - b;\n//..or..\na.Add(b);\n```\n#### Multiplication\n```csharp\n//multiplication with scalar\nMatrix product = a * 3.0;\n//..or..\na.Multiply(3.0);\n//multiplication with another matrix\nMatrix product = a * b;\n//..or..\na.Multiply(b);\n```\n#### Hadamard Product\n```csharp\na.HadamardProduct(b);\n```\n#### Inversion\n```csharp\nMatrix inverse = !a;\n//..or..\na.Inverse();\n```\n#### Transposition\n```csharp\nMatrix r = new Matrix(5, 4);\nr.Transpose();\n```\n#### Mapping elements with a function\n```csharp\nMatrix r = new Matrix(5, 4);\nr.Map(Math.Sin); //Apply Sine function to every matrix element\n//or own function\npublic double MyFunction(double param)\n{\n\treturn param * 42.0;\n}\n\n//[...]\nr.Map(MyFunction);\n//[...]\n```\n### Comparing the matrices\n```csharp\n//Equality\nif(a == b) {}\n//..or..\nif(a != b) {}\n//..or..\nif(a \u003e b) {}\n//..or..\nif(a \u003c b) {}\n//..or..\nif(a \u003e= b) {}\n//..or..\nif(a \u003c= b) {}\n\n```\n### Creating Transformation Matrices\n#### Rotation\n```csharp\n//2D\nMatrix rotation2D = Matrix.Rotation2D(angleInDegrees);\n//3D around X, Y or Z axis\nMatrix rotation3D = Matrix.Rotation3DX(angleInDegrees);\nMatrix rotation3D = Matrix.Rotation3DY(angleInDegrees);\nMatrix rotation3D = Matrix.Rotation3DZ(angleInDegrees);\n```\n#### Scaling\n```csharp\nMatrix scaling = Matrix.Scaling(factorX, factorY, factorZ);\n```\n#### Translation\n```csharp\nMatrix translation = Matrix.Translation(moveX, moveY, moveZ);\n```\n\n\n\n## Fractions\n\n### Creation\n\n```csharp\n//fraction can be created with numerator and denominator as parameters:\nFraction fraction = new Fraction(2, 5);\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\n//Output:\n//Fraction = 2/5\n\n//...or only by numerator part (in this case denominator is 1):\nFraction fraction = new Fraction(2);\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\n//Output:\n//Fraction = 2/1\n\n//...or from string in format \"numerator/denominator\":\nFraction fraction = new Fraction(\"1/5\");\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\n//Output:\n//Fraction = 1/5\n\n//...or from decimal value with accuracy:\nFraction fraction = new Fraction(0.3333, 0.01);\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\n//Output:\n//Fraction = 1/3\n\n//...or from decimal value with default accuracy:\nFraction fraction = new Fraction(0.3333);\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\n//Output:\n//Fraction = 3333/10000\n```\n\n### Assigning the value\n\nValue can be initially assigned at creation, as seen in [previous section](#creation).\nIf value needs to be assigned afterwards afterwards, there are several possible ways.\n\n```csharp\n//...or by using numerator and denominator properties:\nfraction.Numerator = 3;\nfraction.Denominator = 7;\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\n//Output:\n//Fraction = 3/7\n\n//...or by using .AsDouble property:\nfraction.AsDouble = 0.5;\nConsole.WriteLine($\"Fraction = {fraction.ToString()}, AsDouble = {fraction.AsDouble}\");\n//Output:\n//Fraction = 1/2, AsDouble = 0.5\n\n//...or by using .AsFloat property:\nfraction.AsFloat = 0.5f;\nConsole.WriteLine($\"Fraction = {fraction.ToString()}, AsFloat = {fraction.AsFloat}\");\n//Output:\n//Fraction = 1/2, AsFloat = 0.5\n```\n\n### Available Mathematical Operations\n\n#### Addition\n\n```csharp\n//addition of two fractions\nvar fractionOne = new Fraction(1, 5);\nvar fractionTwo = new Fraction(2, 5);\nvar result = fractionOne + fractionTwo;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 15/25, reduced fraction = 3/5\n\n//addition of fraction and number\nresult = fractionOne + 3;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 16/5, reduced fraction = 16/5\n\n//addition of fraction and a decimal number\nresult = fractionOne + 0.5;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 7/10, reduced fraction = 7/10\n```\n\n#### Subtraction\n\n```csharp\n//subtraction of two fractions\nvar fractionOne = new Fraction(1, 5);\nvar fractionTwo = new Fraction(2, 5);\nvar result = fractionOne - fractionTwo;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = -1/5, reduced fraction = -1/5\n\n//subtraction of fraction and number\nresult = fractionOne - 3;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = -14/5, reduced fraction = -14/5\n\n//subtraction of fraction and a decimal number\nresult = fractionOne - 0.5;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = -3/10, reduced fraction = -3/10\n```\n\n#### Multiplication\n\n```csharp\n//multiplication of two fractions\nvar fractionOne = new Fraction(1, 5);\nvar fractionTwo = new Fraction(2, 5);\nvar result = fractionOne * fractionTwo;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 2/25, reduced fraction = 2/25\n\n//multiplication of fraction and number\nresult = fractionOne * 3;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 3/5, reduced fraction = 3/5\n\n//multiplication of fraction and a decimal number\nresult = fractionOne * 0.5;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 1/10, reduced fraction = 1/10\n```\n\n#### Division\n\n```csharp\n//division of two fractions\nvar fractionOne = new Fraction(1, 5);\nvar fractionTwo = new Fraction(2, 5);\nvar result = fractionOne / fractionTwo;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 5/10, reduced fraction = 1/2\n\n//division of fraction and number\nresult = fractionOne / 3;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 1/15, reduced fraction = 1/15\n\n//division of fraction and a decimal number\nresult = fractionOne / 0.5;\nConsole.WriteLine($\"Fraction = {result.ToString()}, reduced fraction = {result.Reduced().ToString()}\");\n//Output:\n//Fraction = 2/5, reduced fraction = 2/5\n```\n\n### Other operations\n\n#### Reduce\n\n```csharp\nvar fraction = new Fraction(3, 15);\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\nfraction.Reduce();\nConsole.WriteLine($\"Fraction reduced = {fraction.ToString()}\");\n//Output:\n//Fraction = 3/15\n//Fraction reduced = 1/5\n```\n\n#### Inverse\n\n```csharp\nfraction = new Fraction(3, 15);\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\nfraction.Inverse();\nConsole.WriteLine($\"Fraction inversed = {fraction.ToString()}\");\nfraction.Reduce();\nConsole.WriteLine($\"Fraction inversed and reduced = {fraction.ToString()}\");\n//Output:\n//Fraction = 3/15\n//Fraction inversed = 15/3\n//Fraction inversed and reduced = 5/1\n```\n\n### Continued Fractions\n\nAlso support for continued fractions is added. Continued fraction can be assigned at fraction creation\nor assigned at runtime.\n\n```csharp\n//...\npublic static class ContinuedFractions\n{\n    public static readonly string e = \"[2;1,2,1,1,4,1,1,6,1,1,8,1,1,10,1,1,12,1,1,14,1,1,16,1,1,18,1,1,20,1,1,22,1,1,24,1,1,26,1,1,28,1,1,30,1,1,32,1,1,34,1,1,36,1,1,38,1,1,40,1,1,42,1,1,44,1,1,46,1,1,48,1,1,50,1,1,52,1,1,54,1,1,56,1,1,58,1,1,60,1,1,62,1,1,64,1,1,66]\";\n    public static readonly string Pi = \"[3;7,15,1,292,1,1,1,2,1,3,1,14,2,1,1,2,2,2,2,1,84,2,1,1,15,3,13,1,4,2,6,6,99,1,2,2,6,3,5,1,1,6,8,1,7,1,2,3,7,1,2,1,1,12,1,1,1,3,1,1,8,1,1,2,1,6,1,1,5,2,2,3,1,2,4,4,16,1,161,45,1,22,1,2,2,1,4,1,2,24,1,2,1,3,1,2,1]\";\n    public static readonly string Phi = \"[1;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]\";\n    public static readonly string Sqrt2 = \"[1;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]\";\n    public static readonly string Sqrt3 = \"[1;1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2]\";\n}\n//...\n\nfraction = new Fraction(ContinuedFractions.e);\nConsole.WriteLine($\"Fraction (e) = {fraction.ToString()}, AsDouble = {fraction.AsDouble}, AsContinuedFraction = {fraction.AsContinuedFraction}\");\n//Output:\n//Fraction (e) = 1264/465, AsDouble = 2,71827956989247, AsContinuedFraction = [2;1,2,1,1,4,1,1,6]\n\nfraction = new Fraction(ContinuedFractions.Pi);\nConsole.WriteLine($\"Fraction (Pi) = {fraction.ToString()}, AsDouble = {fraction.AsDouble}, AsContinuedFraction = {fraction.AsContinuedFraction}\");\n//Output:\n//Fraction (Pi) = 355/113, AsDouble = 3,14159292035398, AsContinuedFraction = [3;7,16]\n\nfraction = new Fraction(Math.PI);\nConsole.WriteLine($\"Fraction (Math.Pi) = {fraction.ToString()}, AsDouble = {fraction.AsDouble}, AsContinuedFraction = {fraction.AsContinuedFraction}\");\n//Output:\n//Fraction (Math.Pi) = 355/113, AsDouble = 3,14159292035398, AsContinuedFraction = [3;7,16]\n\nfraction = new Fraction(ContinuedFractions.Phi);\nConsole.WriteLine($\"Fraction (Phi) = {fraction.ToString()}, AsDouble = {fraction.AsDouble}, AsContinuedFraction = {fraction.AsContinuedFraction}\");\n//Output:\n//Fraction (Phi) = 377/233, AsDouble = 1,61802575107296, AsContinuedFraction = [1;1,1,1,1,1,1,1,1,1,1,2]\n\nfraction = new Fraction(ContinuedFractions.Sqrt2);\nConsole.WriteLine($\"Fraction (Sqrt2) = {fraction.ToString()}, AsDouble = {fraction.AsDouble}, AsContinuedFraction = {fraction.AsContinuedFraction}\");\n//Output:\n//Fraction (Sqrt2) = 577/408, AsDouble = 1,41421568627451, AsContinuedFraction = [1;2,2,2,2,2,2,2]\n\nfraction = new Fraction(ContinuedFractions.Sqrt3);\nConsole.WriteLine($\"Fraction (Sqrt3) = {fraction.ToString()}, AsDouble = {fraction.AsDouble}, AsContinuedFraction = {fraction.AsContinuedFraction}\");\n//Output:\n//Fraction (Sqrt3) = 362/209, AsDouble = 1,73205741626794, AsContinuedFraction = [1;1,2,1,2,1,2,1,3]\n\nfraction = new Fraction(\"[2;1,4,3]\");\nConsole.WriteLine($\"Fraction (45/16) = {fraction.ToString()}, AsDouble = {fraction.AsDouble}, AsContinuedFraction = {fraction.AsContinuedFraction}\");\n//Output:\n//Fraction (45/16) = 45/16, AsDouble = 2,8125, AsContinuedFraction = [2;1,4,3]\n```\n\n### Output\n\nFor output of resulting fraction method ```ToString()``` can be used, which results in a string,\nrepresenting the fraction.\n\n\n```csharp\nfraction = new Fraction(3, 15);\nConsole.WriteLine($\"Fraction = {fraction.ToString()}\");\n//Output:\n//Fraction = 3/15\n```\n\n#### Display Modifiers (Options)\n\nSeveral modifiers can be used. They are sent to ```ToString()``` method as parameter.\nModifiers are in ```DisplayOptions``` enum, described below:\n\n```csharp\n[Flags]\npublic enum DisplayOptions\n{\n    /// \u003csummary\u003eDefault display of fraction (e.g. 2/5 or 31/7)\u003c/summary\u003e\n    None = 0,\n    /// \u003csummary\u003eShow improper fractions (e.g. 7/5) as mixed number (1 2/5)\u003c/summary\u003e\n    ImproperFractionAsMixedNumber = 1,\n    /// \u003csummary\u003eUse unicode superscript and subscript set instead of standard ACSII set for numbers in fraction.\u003c/summary\u003e\n    UseUnicodeCharacters = 2\n}\n\n//...\nprivate static void OutputFractionWithModifiers(Fraction fraction)\n{\n    var builder = new StringBuilder();\n    builder.Append(\"Fraction = \").Append(fraction.ToString());\n    builder.Append(\", as mixed number = \").Append(fraction.ToString(Fraction.DisplayOptions.ImproperFractionAsMixedNumber));\n    builder.Append(\", with Unicode characters = \").Append(fraction.ToString(Fraction.DisplayOptions.UseUnicodeCharacters));\n    builder.Append(\", all modifiers = \").Append(fraction.ToString(Fraction.DisplayOptions.ImproperFractionAsMixedNumber | Fraction.DisplayOptions.UseUnicodeCharacters));\n    Console.WriteLine(builder.ToString());\n}\n//...\n\n//examples of different output options\nfraction = new Fraction(10, 5);\nOutputFractionWithModifiers(fraction);\nfraction = new Fraction(11, 5);\nOutputFractionWithModifiers(fraction);\nfraction = new Fraction(3, 5);\nOutputFractionWithModifiers(fraction);\nfraction = new Fraction(15, -15);\nOutputFractionWithModifiers(fraction);\nfraction = new Fraction(11, 175);\nOutputFractionWithModifiers(fraction);\nfraction = new Fraction(113, 11);\nOutputFractionWithModifiers(fraction);\n//Output (in image):\n```\n\n![foo](doc/DisplayOptionsOutput.png \"Display Options Output\")\n\n\n\n## Easings\n\n### Usage\n\n```csharp\nvar easings = new EasingFunctions();\n\n//quadratic\nvar easedInOutQuad = easings.EaseInOutQuad(x);\n\n//cubic\nvar easedInOutCubic = easings.EaseInOutCubic(x);\n\n//quartic\nvar easedInOutQuart = easings.EaseInOutQuart(x);\n\n//quintic\nvar easedInOutQuint = easings.EaseInOutQuint(x);\n\nvar easedInOutBounce = easings.EaseInOutBounce(x);\nvar easedInOutElastic = easings.EaseInOutElastic(x);\nvar easedInOutExpo = easings.EaseInOutExpo(x);\nvar easedInOutCirc = easings.EaseInOutCirc(x);\nvar easedInOutBack = easings.EaseInOutBack(x);\nvar easedInOutSine = easings.EaseInOutSine(x);\n```\n\n![](doc/Easings.gif)\n\n## Statistics\n\n\n\n## Interpolations\n\n### Usage\n\n```csharp\nusing MathExtended.Interpolations;\n\nvar interpolation = new Interpolation();\ninterpolation.Add(1, 2);\ninterpolation.Add(5, 8);\ninterpolation.Add(7.7, 5);\ninterpolation.Add(10, 15);\ninterpolation.Add(11, 11.3);\n\n//Linear interpolation\ndouble interpolatedValueLinear = interpolation.Linear(3.5);\n//...or...\ninterpolation.Linear();\ndouble interpolatedValueLinear = interpolation.Interpolate(3.5);\n\n//Spline interpolation\ndouble interpolatedValue = interpolation.Spline(3.5);\n//...or...\ninterpolation.Spline();\ndouble interpolatedValue = interpolation.Interpolate(3.5);\t\n\n//Cosine interpolation\ndouble interpolatedValue = interpolation.Cosine(3.5);\n//...or...\ninterpolation.Cosine();\ndouble interpolatedValue = interpolation.Interpolate(3.5);\t\n```\n\n\n\n## Random\n\nPure C# RANMAR Random Number Generator Algorithm Library.\n\n\n\nOriginal ©:\n\n\u003e RANMAR pseudo-random number generator\n\u003e This random number generator originally appeared in \"Toward a Universal\n\u003e Random Number Generator\" by George Marsaglia and Arif Zaman.\n\u003e Florida State University Report: FSU-SCRI-87-50 (1987)\n\u003e It was later modified by F. James and published in \"A Review of Pseudo-\n\u003e random Number Generators\"\n\u003e THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE.\n\u003e (However, a newly discovered technique can yield\n\u003e a period of 10^600. But that is still in the development stage.)\n\u003e It passes ALL of the tests for random number generators and has a period\n\u003e of 2^144, is completely portable (gives bit identical results on all\n\u003e machines with at least 24-bit mantissas in the floating point\n\u003e representation).\n\u003e The algorithm is a combination of a Fibonacci sequence (with lags of 97 and 33, and operation \"subtraction plus one, modulo one\") and an \"arithmetic sequence\" (using subtraction).\n\u003e\n\u003e C language version was written by Jim Butler, and was based on a\n\u003e FORTRAN program posted by David LaSalle of Florida State University.\n\u003e Adapted for Delphi by Anton Zhuchkov (fireton@mail.ru) in February, 2002.\n\u003e Converted into a class by Primoz Gabrijelcic (gabr@17slon.com) in November, 2002.\n\u003e (Url: https://github.com/gabr42/GpDelphiUnits/blob/master/src/GpRandomGen.pas)\n\u003e\n\u003e Adapted for C# by Ales Hotko (https://github.com/ahotko) in May, 2020\n\u003e (from Delphi (gabr42) and C (Url: https://www.pell.portland.or.us/~orc/Code/Misc/random.c))\n\n\n\n### Usage\n\n```csharp\nint factor = 4096 * 4096;\nvar ranmar = new Ranmar(1802, 9373);\n\n//To validate RANMAR generator, use the following procedure (described in original source):\n// - set Seed1 to 1802\n// - set Seed2 to 9373\n// - Generate 20000 random numbers\n// - next 6 generated numbers multiplied by 4096*4096 must be:\n//   6533892, 14220222, 7275067, 6172232, 8354498, 10633180\n\nfor (int i = 0; i \u003c 20006; i++)\n{\n    int generatedNumber = ranmar.Next(factor);\n    if (i \u003c 20000) continue;\n    Console.WriteLine($\"{i + 1}. {generatedNumber}\");\n}\n\n//Output:\n//20001. 6533892\n//20002. 14220222\n//20003. 7275067\n//20004. 6172232\n//20005. 8354498\n//20006. 10633180\n```\n\nAlso ```double``` can be generated:\n```csharp\nConsole.WriteLine($\"Double = {ranmar.NextDouble()}\");\n\n//Output:\n//Double = 0,339674651622772\n```\n\n\n\n## Regressions\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahotko%2Fmathextended","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahotko%2Fmathextended","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahotko%2Fmathextended/lists"}