>From 0 to 2304, Random on seed N+1 produces a double that is less than 0.2 from the output of seed N (out of 0->1). The program hunts for the first N where this is not true, which is 2304. This means the JDK standard Random generator class is not all that random, which is well-known.
On Sun, Feb 20, 2011 at 4:31 PM, Lance Norskog <[email protected]> wrote: > I discovered this when I wanted to make deterministic random vectors > and matrices. To get the same result from each entry on every access, > I can either cache the values or use an algorithm to recreate unique > seed for that entry. I naively just added the coordinate to the base > seed, and created very not-random vectors and matrices. Yes, the JDK > Random is intended to be lame but fast., but this was just too far > over the line. > > Lance > > On Sun, Feb 20, 2011 at 2:31 AM, Dawid Weiss > <[email protected]> wrote: >> 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... >>> >>> >> > > > > -- > Lance Norskog > [email protected] > -- Lance Norskog [email protected]
