All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.math.ntru.polynomial.test.PolynomialGenerator Maven / Gradle / Ivy

There is a newer version: 1.70_1
Show newest version
package org.bouncycastle.pqc.math.ntru.polynomial.test;

import java.util.Random;

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial;

public class PolynomialGenerator
{
    /**
     * Creates a random polynomial with N coefficients
     * between 0 and q-1.
     *
     * @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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy