Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/source/fmpz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ should call :func:`flint_rand_clear` to clean up.

Generates a random integer in the range `0` to `m - 1` inclusive.

.. function:: void fmpz_randm_nonzero(fmpz_t f, flint_rand_t state, const fmpz_t m)

Generates a random integer in the range `1` to `m - 1` inclusive.

.. function:: void fmpz_randtest_mod(fmpz_t f, flint_rand_t state, const fmpz_t m)

Generates a random integer in the range `0` to `m - 1` inclusive, with an
Expand Down
18 changes: 17 additions & 1 deletion doc/source/fmpz_poly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,28 @@ Assignment and basic manipulation
Randomisation
--------------------------------------------------------------------------------

.. function:: void fmpz_mod_poly_rand(fmpz_mod_poly_t f, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx)

Sets `f` to a random polynomial with up to the given length and where
each coefficient has up to the given number of bits. The coefficients
are uniformly generated random numbers in `[0, n)`, where `n` is the modulus given by the context `ctx`.

.. function:: void fmpz_mod_poly_rand_monic(fmpz_mod_poly_t f, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx)

Sets `f` to a random monic polynomial with up to the given length and where
each coefficient has up to the given number of bits. The coefficients
are uniformly generated random numbers in `[0, n)`, where `n` is the modulus given by the context `ctx`.

.. function:: void fmpz_mod_poly_rand_irreducible(fmpz_mod_poly_t f, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx)

Sets `f` to a random irreducible polynomial with up to the given length and where each coefficient has up to the given number of bits. The coefficients
are uniformly generated random numbers in `[0, n)`, where `n` is the modulus given by the context `ctx`.

.. function:: void fmpz_poly_randtest(fmpz_poly_t f, flint_rand_t state, slong len, flint_bitcnt_t bits)

Sets `f` to a random polynomial with up to the given length and where
each coefficient has up to the given number of bits. The coefficients
are signed randomly.
are random numbers in `[1, n)`, where `n` is the modulus given by the context `ctx`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several new things are misplaced here I think. For this specific one, there is no input ctx, for others about they are fmpz_mod_poly but this file is about fmpz_poly.


.. function:: void fmpz_poly_randtest_unsigned(fmpz_poly_t f, flint_rand_t state, slong len, flint_bitcnt_t bits)

Expand Down
1 change: 1 addition & 0 deletions doc/source/mpn_mod.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Basic operations and arithmetic
int mpn_mod_set_mpn(nn_ptr res, nn_srcptr x, slong xn, gr_ctx_t ctx)
int mpn_mod_set_fmpz(nn_ptr res, const fmpz_t x, gr_ctx_t ctx)
int mpn_mod_set_other(nn_ptr res, gr_ptr v, gr_ctx_t v_ctx, gr_ctx_t ctx)
int mpn_mod_rand(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
int mpn_mod_randtest(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
int mpn_mod_write(gr_stream_t out, nn_srcptr x, gr_ctx_t ctx)
int mpn_mod_get_fmpz(fmpz_t res, nn_srcptr x, gr_ctx_t ctx)
Expand Down
15 changes: 13 additions & 2 deletions doc/source/nmod_poly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,25 @@ Assignment and basic manipulation
Randomization
--------------------------------------------------------------------------------

.. function:: void nmod_poly_rand(nmod_poly_t poly, flint_rand_t state, slong len)

Generates a random polynomial with length up to ``len``.

.. function:: void nmod_poly_rand_monic(nmod_poly_t poly, flint_rand_t state, slong len)

Generates a random monic polynomial with length up to ``len``.

.. function:: void nmod_poly_rand_irreducible(nmod_poly_t poly, flint_rand_t state, slong len)

Generates a random irreducible polynomial with length up to ``len``.

.. function:: void nmod_poly_randtest(nmod_poly_t poly, flint_rand_t state, slong len)

Generates a random polynomial with length up to ``len``.
Generates a random and sparse with increased probability polynomial with length up to ``len``.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Generates a random and sparse with increased probability polynomial with length up to ``len``.
Generates a random polynomial with length up to ``len``, with for each coefficient the probability of some special values increased (see :func:`n_randtest`). This function is intended for use in test code.


.. function:: void nmod_poly_randtest_monic(nmod_poly_t poly, flint_rand_t state, slong len)

Generates a random monic polynomial with length ``len``.
Generates a random and sparse with increased probability monic polynomial with length ``len``.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Generates a random and sparse with increased probability monic polynomial with length ``len``.
Generates a random monic polynomial with length ``len``. For each coefficient the probability of some special values is increased (see :func:`n_randtest`). This function is intended for use in test code.


.. function:: void nmod_poly_randtest_trinomial(nmod_poly_t poly, flint_rand_t state, slong len)

Expand Down
7 changes: 5 additions & 2 deletions doc/source/nmod_poly_mat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ Random matrix generation
--------------------------------------------------------------------------------


.. function:: void nmod_poly_mat_rand(nmod_poly_mat_t mat, flint_rand_t state, slong len)

Generates a matrix of polynomials with uniformly generated coefficients.

.. function:: void nmod_poly_mat_randtest(nmod_poly_mat_t mat, flint_rand_t state, slong len)

This is equivalent to applying ``nmod_poly_randtest`` to all entries
in the matrix.
Generates a matrix of polynomials sparse with an increased probability. It is equivalent to apply ``nmod_poly_randtest`` to all entries in the matrix.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Generates a matrix of polynomials sparse with an increased probability. It is equivalent to apply ``nmod_poly_randtest`` to all entries in the matrix.
Generates a matrix of polynomials randomly, with special values increased for each coefficient. This is intended for use in test code and is equivalent to applying ``nmod_poly_randtest`` to all entries in the matrix.


.. function:: void nmod_poly_mat_randtest_sparse(nmod_poly_mat_t A, flint_rand_t state, slong len, float density)

Expand Down
1 change: 1 addition & 0 deletions src/fmpz.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ int _fmpz_is_canonical(const fmpz_t x);
void fmpz_randbits_unsigned(fmpz_t f, flint_rand_t state, flint_bitcnt_t bits);
void fmpz_randbits(fmpz_t f, flint_rand_t state, flint_bitcnt_t bits);
void fmpz_randm(fmpz_t f, flint_rand_t state, const fmpz_t m);
void fmpz_randm_nonzero(fmpz_t f, flint_rand_t state, const fmpz_t m);
void fmpz_randtest(fmpz_t f, flint_rand_t state, flint_bitcnt_t bits);
void fmpz_randtest_unsigned(fmpz_t f, flint_rand_t state, flint_bitcnt_t bits);
void fmpz_randtest_not_zero(fmpz_t f, flint_rand_t state, flint_bitcnt_t bits);
Expand Down
6 changes: 6 additions & 0 deletions src/fmpz/rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ fmpz_randm(fmpz_t f, flint_rand_t state, const fmpz_t m)
}
}

void fmpz_randm_nonzero(fmpz_t f, flint_rand_t state, const fmpz_t m) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behaviour does not have uniform distribution (it is more likely to generate 1 than other values). Maybe generate uniformly in [0,m-2] (being careful with m=1 or such corner cases), and then add 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does m stands for uniform? For me, it stands for modulus since the element is upper bounded by a modulus and is not just a random element with a set number of bits. Sorry, I did not meant to make something uniform.
The functions fmpz_mod_poly_randtest used randm. I prefered creating a randm_nonzero function than using randtest_nonzero.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that currently, fmpz_randm generates a uniform integer in [0, m) (all values have equal probability), as can be seen from the code. The fact that the distribution is uniform is not explicitly indicated in the documentation, but that's ok, it is the "canonical distribution" for a finite set.

So if a fmpz_randm_nonzero function is added, it seems to me that it should also have uniform distribution (choosing uniformly in [1, m)), unless this is tricky to make. In this case it is not tricky: apply fmpz_randm with m-1 to get a uniform choice in [0, m-1), and then add 1, this gives you a uniform choice in [1, m).

fmpz_randm(f, state, m);
if (fmpz_is_zero(f))
fmpz_one(f);
}

void fmpz_randprime(fmpz_t f, flint_rand_t state, flint_bitcnt_t bits, int proved)
{
if (bits <= FLINT_BITS)
Expand Down
9 changes: 9 additions & 0 deletions src/fmpz_mod_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ int fmpz_mod_poly_is_canonical(const fmpz_mod_poly_t A, const fmpz_mod_ctx_t ctx


/* Randomisation ************************************************************/
void fmpz_mod_poly_rand(fmpz_mod_poly_t f, flint_rand_t state,
slong len, const fmpz_mod_ctx_t ctx);

void fmpz_mod_poly_rand_monic(fmpz_mod_poly_t f,
flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx);

void fmpz_mod_poly_rand_irreducible(fmpz_mod_poly_t f,
flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx);


void fmpz_mod_poly_randtest(fmpz_mod_poly_t f, flint_rand_t state,
slong len, const fmpz_mod_ctx_t ctx);
Expand Down
65 changes: 55 additions & 10 deletions src/fmpz_mod_poly/randtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "fmpz_mod_poly.h"
#include "fmpz_mod_poly_factor.h"

void fmpz_mod_poly_randtest(fmpz_mod_poly_t f, flint_rand_t state, slong len,
void fmpz_mod_poly_rand(fmpz_mod_poly_t f, flint_rand_t state, slong len,
const fmpz_mod_ctx_t ctx)
{
slong i;
Expand All @@ -31,7 +31,7 @@ void fmpz_mod_poly_randtest(fmpz_mod_poly_t f, flint_rand_t state, slong len,
_fmpz_mod_poly_normalise(f);
}

void fmpz_mod_poly_randtest_monic(fmpz_mod_poly_t f, flint_rand_t state,
void fmpz_mod_poly_rand_monic(fmpz_mod_poly_t f, flint_rand_t state,
slong len, const fmpz_mod_ctx_t ctx)
{
slong i;
Expand All @@ -48,6 +48,51 @@ void fmpz_mod_poly_randtest_monic(fmpz_mod_poly_t f, flint_rand_t state,
_fmpz_mod_poly_set_length(f, len);
}

void fmpz_mod_poly_rand_irreducible(fmpz_mod_poly_t f, flint_rand_t state,
slong len, const fmpz_mod_ctx_t ctx)
{
if (len == 0)
{
flint_throw(FLINT_ERROR, "Exception (fmpz_mod_poly_randtest_irreducible). len == 0.\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
flint_throw(FLINT_ERROR, "Exception (fmpz_mod_poly_randtest_irreducible). len == 0.\n");
flint_throw(FLINT_ERROR, "Exception (fmpz_mod_poly_rand_irreducible). len == 0.\n");

}

do {
fmpz_mod_poly_rand(f, state, len, ctx);
} while (fmpz_mod_poly_is_zero(f, ctx) ||
!fmpz_mod_poly_is_irreducible(f, ctx));
}

void fmpz_mod_poly_randtest(fmpz_mod_poly_t f, flint_rand_t state, slong len,
const fmpz_mod_ctx_t ctx)
{
slong i;

fmpz_mod_poly_fit_length(f, len, ctx);

for (i = 0; i < len; i++)
fmpz_randm_nonzero(f->coeffs + i, state, fmpz_mod_ctx_modulus(ctx));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could rely on the existing fmpz_randtest_mod instead of fmpz_randm_nonzero?


_fmpz_mod_poly_set_length(f, len);
_fmpz_mod_poly_normalise(f);
}

void fmpz_mod_poly_randtest_monic(fmpz_mod_poly_t f, flint_rand_t state,
slong len, const fmpz_mod_ctx_t ctx)
{
slong i;

FLINT_ASSERT(len > 0);

fmpz_mod_poly_fit_length(f, len, ctx);

for (i = 0; i < len - 1; i++)
fmpz_randm_nonzero(f->coeffs + i, state, fmpz_mod_ctx_modulus(ctx));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also: maybe this could rely on the existing fmpz_randtest_mod instead of fmpz_randm_nonzero?


fmpz_one(f->coeffs + len - 1);

_fmpz_mod_poly_set_length(f, len);
}

static void
fmpz_mod_poly_randtest_monic_sparse(fmpz_mod_poly_t poly, flint_rand_t state,
slong len, slong nonzero, const fmpz_mod_ctx_t ctx)
Expand All @@ -56,9 +101,9 @@ fmpz_mod_poly_randtest_monic_sparse(fmpz_mod_poly_t poly, flint_rand_t state,

fmpz_mod_poly_fit_length(poly, len, ctx);
_fmpz_vec_zero(poly->coeffs, len);
fmpz_randm(poly->coeffs + 0, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm_nonzero(poly->coeffs + 0, state, fmpz_mod_ctx_modulus(ctx));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change, or why using nonzero almost everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have at least a randfull-like functionality. See my comments above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested in other functions, I think that in these randtest functions we may as well rely on the existing fmpz_randtest_mod.

for (i = 1; i < nonzero; i++)
fmpz_randm(poly->coeffs + n_randint(state, len - 1) + 1,
fmpz_randm_nonzero(poly->coeffs + n_randint(state, len - 1) + 1,
state, fmpz_mod_ctx_modulus(ctx));
fmpz_set_ui(poly->coeffs + len - 1, 1);
_fmpz_mod_poly_set_length(poly, len);
Expand Down Expand Up @@ -127,9 +172,9 @@ void fmpz_mod_poly_randtest_trinomial(fmpz_mod_poly_t poly,
ulong k;
fmpz_mod_poly_fit_length(poly, len, ctx);
_fmpz_vec_zero(poly->coeffs, len);
fmpz_randm(poly->coeffs, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm_nonzero(poly->coeffs, state, fmpz_mod_ctx_modulus(ctx));
k = (n_randtest(state) % (len - 2)) + 1;
fmpz_randm(poly->coeffs + k, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm_nonzero(poly->coeffs + k, state, fmpz_mod_ctx_modulus(ctx));
fmpz_one(poly->coeffs + len - 1);
_fmpz_mod_poly_set_length(poly, len);
}
Expand All @@ -139,10 +184,10 @@ void fmpz_mod_poly_randtest_pentomial(fmpz_mod_poly_t poly,
{
fmpz_mod_poly_fit_length(poly, len, ctx);
_fmpz_vec_zero(poly->coeffs, len);
fmpz_randm(poly->coeffs, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm(poly->coeffs + 1, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm(poly->coeffs + 2, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm(poly->coeffs + 3, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm_nonzero(poly->coeffs, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm_nonzero(poly->coeffs + 1, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm_nonzero(poly->coeffs + 2, state, fmpz_mod_ctx_modulus(ctx));
fmpz_randm_nonzero(poly->coeffs + 3, state, fmpz_mod_ctx_modulus(ctx));
fmpz_one(poly->coeffs + len - 1);
_fmpz_mod_poly_set_length(poly, len);
}
Expand Down
2 changes: 2 additions & 0 deletions src/mpn_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mpn_mod_ctx_set_is_field(gr_ctx_t ctx, truth_t is_field)

int gr_ctx_init_mpn_mod(gr_ctx_t ctx, const fmpz_t n);
int _gr_ctx_init_mpn_mod(gr_ctx_t ctx, nn_srcptr n, slong nlimbs);
int mpn_mod_rand(nn_ptr res, flint_rand_t state, gr_ctx_t ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be more like the one just below, gr_ctx_init_mpn_mod_randtest ? Or maybe it is just misplaced and should go later in the file, where mpn_mod_randtest is.

void gr_ctx_init_mpn_mod_randtest(gr_ctx_t ctx, flint_rand_t state);

int mpn_mod_ctx_write(gr_stream_t out, gr_ctx_t ctx);
Expand Down Expand Up @@ -191,6 +192,7 @@ int mpn_mod_div(nn_ptr res, nn_srcptr x, nn_srcptr y, gr_ctx_t ctx);
int _mpn_mod_vec_zero(nn_ptr res, slong len, gr_ctx_t ctx);
int _mpn_mod_vec_clear(nn_ptr FLINT_UNUSED(res), slong FLINT_UNUSED(len), gr_ctx_t FLINT_UNUSED(ctx));
int _mpn_mod_vec_set(nn_ptr res, nn_srcptr x, slong len, gr_ctx_t ctx);
int _mpn_mod_vec_rand(nn_ptr res, flint_rand_t state, slong len, gr_ctx_t ctx);
void _mpn_mod_vec_swap(nn_ptr vec1, nn_ptr vec2, slong len, gr_ctx_t ctx);
int _mpn_mod_vec_neg(nn_ptr res, nn_srcptr x, slong len, gr_ctx_t ctx);
int _mpn_mod_vec_add(nn_ptr res, nn_srcptr x, nn_srcptr y, slong len, gr_ctx_t ctx);
Expand Down
12 changes: 12 additions & 0 deletions src/mpn_mod/ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ mpn_mod_set_other(nn_ptr res, gr_ptr v, gr_ctx_t v_ctx, gr_ctx_t ctx)
return gr_generic_set_other(res, v, v_ctx, ctx);
}

int
mpn_mod_rand(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
{
fmpz_t t;
fmpz_init(t);
fmpz_set_ui_array(t, MPN_MOD_CTX_MODULUS(ctx), MPN_MOD_CTX_NLIMBS(ctx));
fmpz_randm(t, state, t);
GR_IGNORE(mpn_mod_set_fmpz(res, t, ctx));
fmpz_clear(t);
return GR_SUCCESS;
}

int
mpn_mod_randtest(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
{
Expand Down
13 changes: 13 additions & 0 deletions src/mpn_mod/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ _mpn_mod_vec_set(nn_ptr res, nn_srcptr x, slong len, gr_ctx_t ctx)
return GR_SUCCESS;
}

int
_mpn_mod_vec_rand(nn_ptr res, flint_rand_t state, slong len, gr_ctx_t ctx)
{
slong n = MPN_MOD_CTX_NLIMBS(ctx);
slong i;

for (i = 0; i < len; i++)
if (mpn_mod_rand(res + i * n, state, ctx) != GR_SUCCESS)
return GR_UNABLE;

return GR_SUCCESS;
}

void
_mpn_mod_vec_swap(nn_ptr vec1, nn_ptr vec2, slong len, gr_ctx_t ctx)
{
Expand Down
4 changes: 4 additions & 0 deletions src/nmod_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ int nmod_poly_is_monic(const nmod_poly_t poly)

/* Randomisation ************************************************************/

void nmod_poly_rand(nmod_poly_t poly, flint_rand_t state, slong len);
void nmod_poly_rand_monic(nmod_poly_t poly, flint_rand_t state, slong len);
void nmod_poly_rand_irreducible(nmod_poly_t poly, flint_rand_t state, slong len);

void nmod_poly_randtest(nmod_poly_t poly, flint_rand_t state, slong len);

NMOD_POLY_INLINE
Expand Down
28 changes: 28 additions & 0 deletions src/nmod_poly/randtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,34 @@
#include "nmod_poly.h"
#include "nmod_poly_factor.h"

// Rand functions -> random dense polynomials with high probability
void
nmod_poly_rand(nmod_poly_t poly, flint_rand_t state, slong len)
{
nmod_poly_fit_length(poly, len);
_nmod_vec_rand(poly->coeffs, state, len, poly->mod);
poly->length = len;
_nmod_poly_normalise(poly);
}

void
nmod_poly_rand_monic(nmod_poly_t poly, flint_rand_t state, slong len)
{
nmod_poly_fit_length(poly, len);
_nmod_vec_rand(poly->coeffs, state, len - 1, poly->mod);
poly->coeffs[len - 1] = 1;
poly->length = len;
}

void
nmod_poly_rand_irreducible(nmod_poly_t poly, flint_rand_t state, slong len)
{
do {
nmod_poly_rand(poly, state, len);
} while (nmod_poly_is_zero(poly) || !(nmod_poly_is_irreducible(poly)));
}

// Randtest functions -> dense/sparse polynomials
void
nmod_poly_randtest(nmod_poly_t poly, flint_rand_t state, slong len)
{
Expand Down
1 change: 1 addition & 0 deletions src/nmod_poly_mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void nmod_poly_mat_one(nmod_poly_mat_t mat);

/* Random matrices ***********************************************************/

void nmod_poly_mat_rand(nmod_poly_mat_t A, flint_rand_t state, slong len);
void nmod_poly_mat_randtest(nmod_poly_mat_t mat, flint_rand_t state,
slong len);

Expand Down
11 changes: 11 additions & 0 deletions src/nmod_poly_mat/rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
#include "nmod_poly.h"
#include "nmod_poly_mat.h"

void
nmod_poly_mat_rand(nmod_poly_mat_t A, flint_rand_t state, slong len)
{
slong i, j;

for (i = 0; i < A->r; i++)
for (j = 0; j < A->c; j++)
nmod_poly_rand(nmod_poly_mat_entry(A, i, j), state, len);
}


void
nmod_poly_mat_randtest(nmod_poly_mat_t A, flint_rand_t state, slong len)
{
Expand Down
2 changes: 2 additions & 0 deletions src/nmod_vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void _nmod_vec_clear(nn_ptr vec)
}

void _nmod_vec_randtest(nn_ptr vec, flint_rand_t state, slong len, nmod_t mod);
void _nmod_vec_rand(nn_ptr vec, flint_rand_t state, slong len, nmod_t mod);


NMOD_VEC_INLINE
void _nmod_vec_zero(nn_ptr vec, slong len)
Expand Down
7 changes: 7 additions & 0 deletions src/nmod_vec/randtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

#include "nmod_vec.h"

void _nmod_vec_rand(nn_ptr vec, flint_rand_t state, slong len, nmod_t mod)
{
slong i;
for (i = 0; i < len; i++)
vec[i] = n_randint(state, mod.n);
}

void _nmod_vec_randtest(nn_ptr vec, flint_rand_t state, slong len, nmod_t mod)
{
slong i, sparseness;
Expand Down