random-double | An algorithm for generating random doubles
kandi X-RAY | random-double Summary
kandi X-RAY | random-double Summary
The first step was to figure out how to generate numbers in the range [0.0,1.0). Those experiments and the reasoning behind them is in comments and code in rd.c. A few months later I looked at gcc and llvm standard c++ libraries to see if their std::uniform_real_distribution actually solved this problem correctly. They haven't. The result of that is in urd.cxx. The bug report for llvm is here, I haven't made a bug report for gcc. This triggered me to actually figure out how to extend this to arbitrary ranges. The first attempt is documented in comments and code in arbitrary_range.c, but it only deals with positive numbers for now. The nice thing about it is that despite a completely different algorithm the generated numbers from arbitrary_range.c set the exact same bits as the numbers in rd.c which means that either my early assumptions were correct or that my brain farts are at least consistent.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of random-double
random-double Key Features
random-double Examples and Code Snippets
Community Discussions
Trending Discussions on random-double
QUESTION
I was reading java.util.Random
class and noticed that there is no nextDouble()
, nextFloat()
and nextLong()
which can accept a bound.
There are many way to get it done like this.
But my question is why java
did not provide us with these required method like nextInt(int n)
which accept the bound.
Is there any specific reason they did not provide these methods?
...ANSWER
Answered 2017-May-31 at 07:33A good API always tries to provide the essential elements that a user needs to do his job.
Having nextInt(int n)
is just one possible implementation. What if you need other distributions?!
In other words: the Random API could try to anticipate all potential usage patterns, but that would very much bloat the whole API. Instead, the designers choice a very small interface - but you got all the elements required to build your own things on top of that.
Thing is: in the end, this is a design style decision by the people who created the Random class. And as so often, problems could be solved in many different ways. Thus you shouldn't draw deep conclusions on the solution that was picked here.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install random-double
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page