Tim Holloway wrote:The solution (nexInt(n)) / (double) (n - 1)) is questionable because if the random function being used is what I suspect it is (I haven't read the actual official JVM source, but I'm assuming it's based on Knuth), then the nextInt(n) method is actually floor(nextValue(n)*n) in pseudo-code.
In other words, invoking the floating-point random function
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ted Schrey wrote:sorry about the delay.... I'd been sidetracked! I do appreciate all of the input though a lot (most?) of it was over my head .... anyway, i think my post wasn't clear enough. It really is not a matter of precision in this particular case. Rather the conditions of the "problem" stated that "if "0", then no possibility" and if "1" 100% of the time". I think it was a bad set of directions and bypassed it after finding nothing in Java to get an inclusive 1.... and I do see why. That would make no sense, because if 0 is inclusive, then 1 is past the upper limit. Sorrowful example, but I think it's like the 1st century can only go up to midnight of the 99th year.... once it reaches 100, it's the next century. Thank you once again.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Bad analogy, I am afraid. Year numbers are like counting numbers; you go from 1 to 100. Imagine that Math#random returned a value between 0.000000000000001 and 1.0 inclusive.Ted Schrey wrote:. . . it's like the 1st century can only go up to midnight of the 99th year.... once it reaches 100, it's the next century. . . .
Stephan van Hulst wrote:?
Didn't we start counting the 20th century at 1900, and ended at 1999?
I hadn't been here for fifteen years
Otherwise the 20th century would have had no years starting 20.A.J. Côté wrote:. . . 20th century . . . 2000
A.J. Côté wrote:
Stephan van Hulst wrote:?
Didn't we start counting the 20th century at 1900, and ended at 1999?
Nope, 20th century began January 1, 1901 and ended December 31, 2000
I hadn't been here for fifteen years
It is only since the advent of numeric datatypes limited in the number of digits available that counting from 0…99 became necessary. On an old cash register which I remember from when I was little, it might have been impossible to ring up £2. It was however possible to ring up £1/19/11¾ which was the largest amount possible with the number of wheels/labels available to show the sum.Stephan van Hulst wrote:. . . the programmer inside me weeps.
A.J. Côté wrote:Funnily enough, the 3th millennium started January 1, 2001 so all the 2000 celebretions were a year early.
Campbell Ritchie wrote:On an old cash register which I remember from when I was little, it might have been impossible to ring up £2. It was however possible to ring up £1/19/11¾ which was the largest amount possible with the number of wheels/labels available to show the sum.
Winston Gutkowski wrote:
However, as I tried to explain, there's no guarantee that nextDouble() would ever return 0.0 either, even though it's theoretically in the range - and a test to find out whether it does could take a very long time. .
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:Actually there is a guarantee that nextDouble can return 0.0. It's part of the spec.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:...and that would assume that Random's LCG generates a perfect spread of numbers for its seed, which seems highly unlikely).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Guillermo Ishi wrote:You can get a truly random number by reading milliseconds from a timer or clock register that rolls over, if it's read at random times such as a person coming up and interacting with the program.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:For anyone who's interested (Ted, Tim?), I discovered this page about a family of RNGs called "Xorshift"...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Don't get me started about those stupid light bulbs. |