A perhaps better question is what are you trying to prove or what was your original intention? :) This is a very strange program indeed -- what it does is basically check what the next double value from a fixed initial seed is... since random uses a relatively simple congruential algorithm, the result isn't really that surprising (to me?).
Dawid On Sun, Feb 20, 2011 at 2:51 AM, Lance Norskog <[email protected]> wrote: > What does this program print? > > > package hack; > > import java.util.Random; > > public class JDKRandomThreatOrMenace { > > public static void main(String[] args) { > Random rnd = new Random(0); > > double last = rnd.nextDouble(); > long i = 1; > for(; i < Long.MAX_VALUE; i++) { > rnd.setSeed(i); > double next = rnd.nextDouble(); > if (Math.abs(next - last) > 0.2) > break; > } > System.out.println(i); > } > > } > > Your prize if you get it right? A patch would be welcome... > >
