diff options
Diffstat (limited to 'core/src/test/java/org/spongycastle/pqc/math/ntru/polynomial/test/PolynomialGenerator.java')
-rw-r--r-- | core/src/test/java/org/spongycastle/pqc/math/ntru/polynomial/test/PolynomialGenerator.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/src/test/java/org/spongycastle/pqc/math/ntru/polynomial/test/PolynomialGenerator.java b/core/src/test/java/org/spongycastle/pqc/math/ntru/polynomial/test/PolynomialGenerator.java new file mode 100644 index 00000000..a30fea4d --- /dev/null +++ b/core/src/test/java/org/spongycastle/pqc/math/ntru/polynomial/test/PolynomialGenerator.java @@ -0,0 +1,27 @@ +package org.spongycastle.pqc.math.ntru.polynomial.test; + +import java.util.Random; + +import org.spongycastle.pqc.math.ntru.polynomial.IntegerPolynomial; + +public class PolynomialGenerator +{ + /** + * Creates a random polynomial with <code>N</code> coefficients + * between <code>0</code> and <code>q-1</code>. + * + * @param N length of the polynomial + * @param q coefficients will all be below this number + * @return a random polynomial + */ + public static IntegerPolynomial generateRandom(int N, int q) + { + Random rng = new Random(); + int[] coeffs = new int[N]; + for (int i = 0; i < N; i++) + { + coeffs[i] = rng.nextInt(q); + } + return new IntegerPolynomial(coeffs); + } +}
\ No newline at end of file |