You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Major refactor of NumSharp's random sampling module to achieve 1-to-1 parity with NumPy 2.x. This includes replacing the RNG engine, implementing 25 missing distributions, and standardizing the API surface.
Problem
NumSharp's np.random.* had several critical misalignments with NumPy:
Different RNG algorithm — NumSharp used .NET's Subtractive Generator (Knuth), while NumPy uses Mersenne Twister (MT19937). Same seed produced completely different sequences.
Missing distributions — Only ~10 of NumPy's 35+ distributions were implemented.
Inconsistent API — Size parameters, scalar returns, and validation differed from NumPy behavior.
No long indexing — Size parameters used int instead of long, limiting array sizes.
Proposal
RNG Engine Replacement
Implement MT19937 (Mersenne Twister) to match NumPy's random state
Add NextGaussian() for Box-Muller transform (normal distribution)
Overview
Major refactor of NumSharp's random sampling module to achieve 1-to-1 parity with NumPy 2.x. This includes replacing the RNG engine, implementing 25 missing distributions, and standardizing the API surface.
Problem
NumSharp's
np.random.*had several critical misalignments with NumPy:Different RNG algorithm — NumSharp used .NET's Subtractive Generator (Knuth), while NumPy uses Mersenne Twister (MT19937). Same seed produced completely different sequences.
Missing distributions — Only ~10 of NumPy's 35+ distributions were implemented.
Inconsistent API — Size parameters, scalar returns, and validation differed from NumPy behavior.
No long indexing — Size parameters used
intinstead oflong, limiting array sizes.Proposal
RNG Engine Replacement
NextGaussian()for Box-Muller transform (normal distribution)np.random.seed(42)produces identical sequencesMissing Distributions (25 new)
weibull,standard_cauchy,vonmises,f,logseriesstandard_normal,standard_t,triangulardirichlet,gumbel,hypergeometric,laplace,logisticmultinomial,multivariate_normal,negative_binomialnoncentral_chisquare,noncentral_f,pareto,powerrayleigh,standard_exponential,standard_gammawald,zipfAPI Standardization
UnmanagedMemoryBlockint[]+params long[]Multivariate Normal Fix
Evidence
Before (seed=42, first value):
rand()randn()randint(0,10)After:
All functions produce identical sequences to NumPy given the same seed.
Scope / Non-goals
In scope:
np.random.*API (RandomState-style)Not in scope:
GeneratorAPI (np.random.default_rng())BitGeneratorarchitectureBreaking Changes
params int[]removedrand(5, 10)no longer compilesrand(5L, 10L)orrand(new Shape(5, 10))rand().GetDouble()→rand().GetDouble(0)[0]or use.GetValue()Benchmark / Performance
UnmanagedMemoryBlockmigration eliminates managed array allocationsRelated Issues
longindexingbranch forlongarray indexing supportGeneratorAPI (NumPy 1.17+ style)Summary
NUMPY_RANDOM.md,RANDOM_MIGRATION_PLAN.md