Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8025909 Lambda Library Spec Updates
  3. JDK-8025148

Clarify SplittableRandom spec for generated values from parallel streams

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • core-libs
    • Windows7x64, JDK8 b107 x64

    • Fix Understood
    • b107
    • 8
    • x86
    • windows_7

      Following code:

      import java.util.*;

      public class Test {

          public static void main(String[] args) {
              StringJoiner expected = new StringJoiner("\n");
              expected.add("expected:");

              StringJoiner actual = new StringJoiner("\n");
              actual.add("actual:");

              Iterator<Double> i = new SplittableRandom(0).doubles(8).distinct().iterator();
              while (i.hasNext()) {
                  expected.add(String.valueOf(i.next()));
              }

              i = new SplittableRandom(0).doubles(8).distinct().parallel().iterator();
              while (i.hasNext()) {
                  actual.add(String.valueOf(i.next()));
              }

              System.out.println(expected);
              System.out.println(actual);
          }
      }

      Produces following output:

      expected:
      0.6118225421857174
      0.8243869101616611
      0.8435259660697864
      0.4175532166907524
      0.1350922166954046
      0.13871074418376472
      0.24279104418383668
      0.2419412935695664
      actual:
      0.10047975177649981
      0.4886723680988455
      0.24952460161236745
      0.2001101735985169
      0.4175532166907524
      0.8603064296150352
      0.7058812188621817
      0.13950492113400426

      However we should have received the identical result according to following assertion from specification:

      Except for operations identified as explicitly nondeterministic, such as findAny(), whether a stream executes sequentially or in parallel should not change the result of the computation.

      This assertion could be found here:
      http://jre.us.oracle.com/java/re/jdk/8/promoted/latest/doc/api/java/util/stream/package-summary.html

            psandoz Paul Sandoz
            grakov Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: