Comments (4)
Also, I would suggest to check if max == 1 << 32
and directly return nextRaw32()
in that case, which is more efficient because it saves the modulo and other operations. This might be usefull if a packages uses nextInt on the Random
class (so without a dependency on xrandom
) to get random bits. Then the user of that package could supply an Xrandom()
as a generator and get slightly better performance.
from xrandom_dart.
That's right, the range limits are fixed in the new release (0.7.1).
from xrandom_dart.
Also, I would suggest to check if
max == 1 << 32
and directly returnnextRaw32()
We literally have only one max
value, at which such nextInt
will work noticeably faster. But there are more than four billion possible max
values, at which such a nextInt
will become slightly slower.
I have doubts that such an optimization is appropriate. Especially considering that for a particular max == 1 << 32
there is a public nextRaw32
method. And the nextRaw32
is apparently even faster than an optimized nextInt
would be.
Now the user has the opportunity to create a class that inherits Xrandom
and overload the nextInt
method with optimization for nextRaw32
. I think it's worth leaving that decision to the user, whether they need it.
from xrandom_dart.
I am currently writing a package that implements an extension on Random
which adds a bunch of methods for generating random values of various types, for example BigInt
or Uint8List
. And since I don't want to add a dependeny to xrandom and the extension should work on any Random
, I am using nextInt(1 << 32)
a lot to generate random bytes. (And likely others do this too.) But i see that you have added a special case for all powers of two, which is even better. (The two extra &
and -
operations likely have absolutely negligible impact on performance.)
from xrandom_dart.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xrandom_dart.