Skip to content

Commit

Permalink
test bigLFSR
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Dec 17, 2024
1 parent 643b63a commit 38f4965
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fun makeBigIntFromTaps(taps: List<Int>): BigInteger =
}.reduce { a, c -> a.or(c) }.or(BigInteger.ONE)

fun makeRandBigInt(len: Int): BigInteger =
BigInteger.parseString(Array(len) { if(Random.nextBoolean()) '1' else '0' }.joinToString(""), 2) + 1
BigInteger.parseString(Array(len) { if (it == 0) '1' else if (Random.nextBoolean()) '1' else '0' }.joinToString(""), 2) + 1

class BigLFSR(primitivePoly: BigInteger, val start: BigInteger = BigInteger.ONE) {
private val taps: BigInteger = primitivePoly.shr(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ai.hypergraph.kaliningraph.sampling
import ai.hypergraph.kaliningraph.choose
import ai.hypergraph.kaliningraph.types.times
import kotlin.math.pow
import kotlin.random.Random
import kotlin.test.*

/*
Expand Down Expand Up @@ -35,6 +36,14 @@ class SamplingTest {
assertEquals(2.0.pow(i).toInt(), distinct.size + 1)
}

/*
./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.sampling.SamplingTest.testBigLFSR"
*/
@Test
fun testBigLFSR() =
listOf(11, 101, 1_001, 10_001, 100_001).map { it + 2 * it * Random.nextDouble().toInt() }
.forEach { i -> assertEquals(i, bigLFSRSequence(i).toList().distinct().size) }

/*
./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.sampling.SamplingTest.testMDSampler"
*/
Expand Down

0 comments on commit 38f4965

Please sign in to comment.