In regard to providing the long to seed java.util.Random, if I instantiate the object once, it seems that if I just take the time as a seed that will be satisfactory for the life of the program, which for my purpose means that the result of a series of calls to nextDouble() looks random.
Suppose for reasons of code simplicity, I instantiate Random, use it several times, then re-instantiate, and repeat. If the seed is provided similarly, the seeds will be similar and increasing because it is based on the time. The increases will be small compared to the value if it is the number of seconds since January 1, 1970. (Edit: This question was asked in the year 2011.)
If I chain the output of nextDouble() does the re-instantiation of Random with a non-random time-based seed cause a subtle pattern to appear in the composite chain of output from nextDouble(). Another way to phrase this question is: do I need a seed drawn uniformly from the set of long.
You probably are likely to run into a situation like this where indeed they will get assigned the same seed, particuarly if they’re created in the same millisecond. Some machines ahve a resolution as low as 15 milliseconds or more, so it becomes an even bigger problem.
One way toget around this is to use
Math.random(). It uses a system wide random instance that only ever gets instantiated the first time it’s used. I don’t believe you have access to the underlying instance, so you can’t use it to getnextInt()but you can useMath.random()for doubles, or if you really want your own Random object, get adoublefromMath.random(), convert its bits into alongand use thatlongas your seed for your newRandom.Oracle docs for random can be found here.