Skip to content

Commit 400598a

Browse files
committed
Add a rand function to mpn_mod
1 parent bb5d986 commit 400598a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

doc/source/mpn_mod.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Basic operations and arithmetic
109109
int mpn_mod_set_mpn(nn_ptr res, nn_srcptr x, slong xn, gr_ctx_t ctx)
110110
int mpn_mod_set_fmpz(nn_ptr res, const fmpz_t x, gr_ctx_t ctx)
111111
int mpn_mod_set_other(nn_ptr res, gr_ptr v, gr_ctx_t v_ctx, gr_ctx_t ctx)
112+
int mpn_mod_rand(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
112113
int mpn_mod_randtest(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
113114
int mpn_mod_write(gr_stream_t out, nn_srcptr x, gr_ctx_t ctx)
114115
int mpn_mod_get_fmpz(fmpz_t res, nn_srcptr x, gr_ctx_t ctx)

src/mpn_mod/ring.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@ mpn_mod_set_other(nn_ptr res, gr_ptr v, gr_ctx_t v_ctx, gr_ctx_t ctx)
202202
return gr_generic_set_other(res, v, v_ctx, ctx);
203203
}
204204

205+
int
206+
mpn_mod_rand(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
207+
{
208+
fmpz_t t;
209+
fmpz_init(t);
210+
fmpz_set_ui_array(t, MPN_MOD_CTX_MODULUS(ctx), MPN_MOD_CTX_NLIMBS(ctx));
211+
fmpz_randm(t, state, t);
212+
GR_IGNORE(mpn_mod_set_fmpz(res, t, ctx));
213+
fmpz_clear(t);
214+
return GR_SUCCESS;
215+
}
216+
205217
int
206218
mpn_mod_randtest(nn_ptr res, flint_rand_t state, gr_ctx_t ctx)
207219
{

0 commit comments

Comments
 (0)