random streams (original) (raw)

Brian Goetz brian.goetz at oracle.com
Mon Dec 31 11:49:47 PST 2012


(Initially, thread-local randoms were available only as a utility method in FJ, then made stand-alone for JDK7.) We'd sorta rather not let this lesson be lost :-)

Right. Of course, we have this problem today with Random.nextInt. Is your argument that Random.ints() will be such an attractive nuisance that the situation is going to be far worse than with the existing Random/ThreadLocalRandom divide?

ThreadLocalRandom can override this to implement:

public IntStream ints() { return PrimitiveStreams.repeatedly( () -> TLR.current().nextInt()); } How about ONLY adding to TLR?

Several potential objections come to mind:

These basically boil down to "seems kinda like we're hosing the folks who just want a serial stream of random numbers for test programs, just because someone might misuse it in the parallel case (in exactly the same way they can still misuse it without stream sugar.)"



More information about the lambda-libs-spec-experts mailing list