Search in sources :

Example 1 with NativeRandom

use of org.nd4j.rng.NativeRandom in project nd4j by deeplearning4j.

the class RandomTests method testStepOver3.

@Test
public void testStepOver3() throws Exception {
    Random random = Nd4j.getRandomFactory().getNewRandomInstance(119);
    if (random instanceof NativeRandom) {
        NativeRandom rng = (NativeRandom) random;
        assertTrue(rng.getBufferSize() > 1000000L);
        int someInt = rng.nextInt();
        for (int e = 0; e < 10000; e++) rng.nextInt();
        random.setSeed(119);
        int sameInt = rng.nextInt();
        assertEquals(someInt, sameInt);
        random.setSeed(120);
        int otherInt = rng.nextInt();
        assertNotEquals(someInt, otherInt);
    } else
        log.warn("Not a NativeRandom object received, skipping test");
}
Also used : NativeRandom(org.nd4j.rng.NativeRandom) Random(org.nd4j.linalg.api.rng.Random) DefaultRandom(org.nd4j.linalg.api.rng.DefaultRandom) NativeRandom(org.nd4j.rng.NativeRandom) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest) Test(org.junit.Test)

Example 2 with NativeRandom

use of org.nd4j.rng.NativeRandom in project nd4j by deeplearning4j.

the class RandomTests method testStepOver2.

@Test
public void testStepOver2() throws Exception {
    Random random = Nd4j.getRandomFactory().getNewRandomInstance(119);
    if (random instanceof NativeRandom) {
        NativeRandom rng = (NativeRandom) random;
        assertTrue(rng.getBufferSize() > 1000000L);
        assertEquals(0, rng.getPosition());
        rng.nextLong();
        assertEquals(1, rng.getPosition());
        assertEquals(1, rng.getGeneration());
        for (long e = 0; e <= rng.getBufferSize(); e++) {
            rng.nextLong();
        }
        assertEquals(2, rng.getPosition());
        assertEquals(2, rng.getGeneration());
        rng.reSeed(8792);
        assertEquals(2, rng.getGeneration());
        assertEquals(2, rng.getPosition());
    } else
        log.warn("Not a NativeRandom object received, skipping test");
}
Also used : NativeRandom(org.nd4j.rng.NativeRandom) Random(org.nd4j.linalg.api.rng.Random) DefaultRandom(org.nd4j.linalg.api.rng.DefaultRandom) NativeRandom(org.nd4j.rng.NativeRandom) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)2 DefaultRandom (org.nd4j.linalg.api.rng.DefaultRandom)2 Random (org.nd4j.linalg.api.rng.Random)2 NativeRandom (org.nd4j.rng.NativeRandom)2