kronenthaler / libai

4 stars 2 forks source link

Change currentTimeMillis() for nanoTime() #13

Closed dktcoding closed 7 years ago

dktcoding commented 7 years ago

I've been writing and running some tests and found a somewhat troubling behavior, multiple invocations to Matrix.random() will return the exact same matrix...

    @Test
    public void testRandomIntInt() {
        Matrix a = Matrix.random(15, 10);
        Matrix b = Matrix.random(15, 10);
        assertNotEquals(a, b);
    }

This is actually fascinating, I wrote the tests on my laptop and the work perfectly and when I got home they didn't work (I don't own a very good laptop...),

The proposed change is simply to make the tests work, but in the future I much rather pass a Random object to random initializers, and use ThreadLocalRandom.current() for uninitialized random objects.

kronenthaler commented 7 years ago

I have seen this behavior before in java applications, it depends on the host OS the implementation of currentMillis. In linux it works as expected, whereas in windows the the currentMillis doesn't give milliseconds but just seconds.