Skip to content

Commit bb5d986

Browse files
committed
Add fmpz_mod_vec_rand
1 parent cacfb53 commit bb5d986

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/fmpz_mod_vec.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Conversions
88

99
.. function:: void _fmpz_mod_vec_set_fmpz_vec(fmpz * A, const fmpz * B, slong len, const fmpz_mod_ctx_t ctx)
1010

11-
Set the `fmpz_mod_vec` `(A, len)` to the `fmpz_vec` `(B, len)` after
11+
Set the `fmpz_{mod}_{vec}` `(A, len)` to the `fmpz_{vec}` `(B, len)` after
1212
reduction of each entry modulo the modulus..
1313

1414
Arithmetic
@@ -61,3 +61,10 @@ Multiplication
6161
.. function:: void _fmpz_mod_vec_mul(fmpz * A, const fmpz * B, const fmpz * C, slong len, const fmpz_mod_ctx_t ctx)
6262

6363
Set `(A, len)` the pointwise multiplication of `(B, len)` and `(C, len)`.
64+
65+
Random functions
66+
--------------------------------------------------------------------------------
67+
68+
.. function:: void _fmpz_mod_vec_rand(fmpz * A, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx)
69+
70+
Sets ``vec`` to a vector of the given length with entries picked uniformly at random in `[0, mod.n)`.

src/fmpz_mod_vec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void _fmpz_mod_vec_dot(fmpz_t d, const fmpz * A, const fmpz * B,
5555
void _fmpz_mod_vec_dot_rev(fmpz_t r, const fmpz * a,
5656
const fmpz * b, slong len, const fmpz_mod_ctx_t ctx);
5757

58+
void _fmpz_mod_vec_rand(fmpz *A, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx);
59+
5860
#ifdef __cplusplus
5961
}
6062
#endif

src/fmpz_mod_vec/rand.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "fmpz.h"
2+
#include "fmpz_mod.h"
3+
#include "fmpz_mod_vec.h"
4+
5+
void _fmpz_mod_vec_rand(fmpz *A, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx)
6+
{
7+
slong i;
8+
for (i = 0; i < len; i++)
9+
fmpz_randm(A + i, state, fmpz_mod_ctx_modulus(ctx));
10+
}

0 commit comments

Comments
 (0)