flyingmutant / rand Goto Github PK
View Code? Open in Web Editor NEWFast, high quality alternative to math/rand and golang.org/x/exp/rand
Home Page: https://pkg.go.dev/pgregory.net/rand
License: Mozilla Public License 2.0
Fast, high quality alternative to math/rand and golang.org/x/exp/rand
Home Page: https://pkg.go.dev/pgregory.net/rand
License: Mozilla Public License 2.0
Implementation in math/rand
(and golang.org/x/exp/rand
) suffers from a correlation: see golang/go#8731 and An improved ziggurat method to generate normal random samples for analysis. Also, they can probably be made faster.
#2 is about a general purpose Sample
, but a relatively common case is func Pick2(n int) (i int, j int)
. Is it worth adding as a separate function, given that it will only be marginally better than a straightforward loop-based implementation?
Hi there!
Do you have some benchmarks regarding https://github.com/valyala/fastrand ?
In "global_go119.go", maphash.Bytes(maphash.MakeSeed(), nil)
can not generate zero, because rthash(nil, 0, state)
returns state
directly and state
must not be 0.
Sample
was added in ce7c277, however there are several problematic things:
Sample
was inline and the k
is constant (!); see:
Perm
Rand
increases its size, and introduces a pointer in a previously pointer-free structShuffle
if requiredPartialShuffle
is much faster and guarantees random order (although it requires mutable slice of size n
)Perm
, Sample
, PartialShuffle
and Shuffle
is maybe too muchOn the other hand, Sample
runs in O(k) for both time and memory. Also, algorithm is simple but non-obvious (a bit like Shuffle
), as is the linear-search-instead-of-map optimization.
Also, with #1, Sample
may be not required at all.
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.