pomma89 / troschuetz.random Goto Github PK
View Code? Open in Web Editor NEWFully managed library providing various random number generators and distributions.
Home Page: https://gitlab.com/pomma89/troschuetz-random
Fully managed library providing various random number generators and distributions.
Home Page: https://gitlab.com/pomma89/troschuetz-random
As https://msdn.microsoft.com/en-us/library/2dx6wyd4(v=vs.110).aspx mentioned:
Remarks
The Next(Int32,βInt32) overload returns random integers that range from minValue to maxValue β 1. However, if maxValue equals minValue, the method returns minValue.
It should not raise an exception when (minValue == maxValue).
In the following scenario, results
will always be { 0, 100000, 0, 0 }
.
var results = new int[4];
for (int x = 0; x < 100000; x++)
{
var rnd = new TRandom();
results[rnd.Next(4)]++;
}
In the next scenario, results
will be something like { 24971, 124881, 25068, 25080 }
.
var results = new int[4];
for (int x = 0; x < 100000; x++)
{
var rnd = new TRandom();
results[rnd.Next(4)]++;
results[rnd.Next(4)]++;
}
So the first roll is always 1. The second is sufficiently random.
Looking at IGenerator, I see that Next()
produces an int between 0, and int.MaxValue
exclusive, and NextInclusiveMaxValue()
is between 0 and int.MaxValue
inclusive. Looking at the uint
functions, I see the opposite: NextUInt()
produces a value between 0 and uint.MaxValue
inclusive, whereas NextUIntExclusiveMaxValue()
produces a value between 0 and uint.MaxValue
exclusive.
Why does NextUInt()
default to an inclusive bound, whereas Next()
defaults to an exclusive bound? At first glance it seems a little unintuitive -- I would expect that both would default to the same bounds behavior, if there is no reason to do otherwise.
I have implemented MT19937 in C# according to the code in wikipedia and wanted to verify results with your implementation, but they were wrong.
I narrowed it to the line
https://github.com/pomma89/Troschuetz.Random/blob/fe9423531c158ee01ad1d16515f186fb5d7ac9ca/src/Troschuetz.Random/Generators/MT19937Generator.cs#L353
It reduces random number range from 32 to 31 bits.
In wikipedia case it is
y := y xor (y >> l)
return lowest w bits of (y)
Notice it is "L" (18) not 1.
that I translated as
y = y ^ (y >> l);
return 0xffffffffU & y;
Notice that your results are also different from the online test
I would like to use this library in a project that is under MIT. Do you think it would be feasible to change the license of Troschuetz.Random to MIT?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.