IDSIA / crema

Crema: Credal Models Algorithms
https://crema-toolbox.readthedocs.io/
GNU Lesser General Public License v3.0
10 stars 4 forks source link

Random seed for ArraysUtil::shuffle #82

Closed rcabanasdepaz closed 3 years ago

rcabanasdepaz commented 3 years ago

The methods ArraysUtil::shuffle do not use the global Random object and hence the it cannot be replicated. An so it happens with the derived methods.

The following code does not always produces the same result, though it should.

        RandomUtil.setRandomSeed(10);
        VertexFactor vfi = VertexFactorUtilities.random(Strides.as(0,3), 3);
        System.out.println(vfi);

        BayesianFactor bf = BayesianFactorUtilities.random(Strides.as(0,3), Strides.empty());
        System.out.println(bf);

        double[] v = RandomUtil.sampleNormalized(3);
        System.out.println(Arrays.toString(v));

        double[] v2 = new double[]{0,1,2,3,4};
        ArraysUtil.shuffle(v2);
        System.out.println(Arrays.toString(v2));