Skip to content

Commit eafe4cf

Browse files
committed
Replace randm_non_zero by randtest calls
1 parent 59f5c7d commit eafe4cf

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/fmpz_mod_poly/randtest.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ void fmpz_mod_poly_randtest(fmpz_mod_poly_t f, flint_rand_t state, slong len,
6969

7070
fmpz_mod_poly_fit_length(f, len, ctx);
7171

72-
for (i = 0; i < len; i++)
73-
fmpz_randm_nonzero(f->coeffs + i, state, fmpz_mod_ctx_modulus(ctx));
72+
for (i = 0; i < len; i++) {
73+
fmpz_randtest_unsigned(f->coeffs + i, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
74+
fmpz_mod(f->coeffs + i, f->coeffs + i, fmpz_mod_ctx_modulus(ctx));
75+
}
7476

7577
_fmpz_mod_poly_set_length(f, len);
7678
_fmpz_mod_poly_normalise(f);
@@ -85,8 +87,10 @@ void fmpz_mod_poly_randtest_monic(fmpz_mod_poly_t f, flint_rand_t state,
8587

8688
fmpz_mod_poly_fit_length(f, len, ctx);
8789

88-
for (i = 0; i < len - 1; i++)
89-
fmpz_randm_nonzero(f->coeffs + i, state, fmpz_mod_ctx_modulus(ctx));
90+
for (i = 0; i < len - 1; i++) {
91+
fmpz_randtest_unsigned(f->coeffs + i, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
92+
fmpz_mod(f->coeffs + i, f->coeffs + i, fmpz_mod_ctx_modulus(ctx));
93+
}
9094

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

@@ -101,10 +105,13 @@ fmpz_mod_poly_randtest_monic_sparse(fmpz_mod_poly_t poly, flint_rand_t state,
101105

102106
fmpz_mod_poly_fit_length(poly, len, ctx);
103107
_fmpz_vec_zero(poly->coeffs, len);
104-
fmpz_randm_nonzero(poly->coeffs + 0, state, fmpz_mod_ctx_modulus(ctx));
105-
for (i = 1; i < nonzero; i++)
106-
fmpz_randm_nonzero(poly->coeffs + n_randint(state, len - 1) + 1,
107-
state, fmpz_mod_ctx_modulus(ctx));
108+
fmpz_randtest_unsigned(poly->coeffs + 0, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
109+
fmpz_mod(poly->coeffs + 0, poly->coeffs + 0, fmpz_mod_ctx_modulus(ctx));
110+
for (i = 1; i < nonzero; i++) {
111+
ulong random_idx = n_randint(state, len - 1);
112+
fmpz_randtest_unsigned(poly->coeffs + random_idx + 1, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
113+
fmpz_mod(poly->coeffs + random_idx + 1, poly->coeffs + random_idx + 1, fmpz_bits(fmpz_mod_ctx_modulus(ctx)));
114+
}
108115
fmpz_set_ui(poly->coeffs + len - 1, 1);
109116
_fmpz_mod_poly_set_length(poly, len);
110117
}
@@ -172,9 +179,11 @@ void fmpz_mod_poly_randtest_trinomial(fmpz_mod_poly_t poly,
172179
ulong k;
173180
fmpz_mod_poly_fit_length(poly, len, ctx);
174181
_fmpz_vec_zero(poly->coeffs, len);
175-
fmpz_randm_nonzero(poly->coeffs, state, fmpz_mod_ctx_modulus(ctx));
182+
fmpz_randtest_unsigned(poly->coeffs, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
183+
fmpz_mod(poly->coeffs, poly->coeffs, fmpz_mod_ctx_modulus(ctx));
176184
k = (n_randtest(state) % (len - 2)) + 1;
177-
fmpz_randm_nonzero(poly->coeffs + k, state, fmpz_mod_ctx_modulus(ctx));
185+
fmpz_randtest_unsigned(poly->coeffs + k, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
186+
fmpz_mod(poly->coeffs + k, poly->coeffs + k, fmpz_mod_ctx_modulus(ctx));
178187
fmpz_one(poly->coeffs + len - 1);
179188
_fmpz_mod_poly_set_length(poly, len);
180189
}
@@ -184,10 +193,14 @@ void fmpz_mod_poly_randtest_pentomial(fmpz_mod_poly_t poly,
184193
{
185194
fmpz_mod_poly_fit_length(poly, len, ctx);
186195
_fmpz_vec_zero(poly->coeffs, len);
187-
fmpz_randm_nonzero(poly->coeffs, state, fmpz_mod_ctx_modulus(ctx));
188-
fmpz_randm_nonzero(poly->coeffs + 1, state, fmpz_mod_ctx_modulus(ctx));
189-
fmpz_randm_nonzero(poly->coeffs + 2, state, fmpz_mod_ctx_modulus(ctx));
190-
fmpz_randm_nonzero(poly->coeffs + 3, state, fmpz_mod_ctx_modulus(ctx));
196+
fmpz_randtest_unsigned(poly->coeffs, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
197+
fmpz_mod(poly->coeffs, poly->coeffs, fmpz_mod_ctx_modulus(ctx));
198+
fmpz_randtest_unsigned(poly->coeffs + 1, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
199+
fmpz_mod(poly->coeffs + 1, poly->coeffs + 1, fmpz_mod_ctx_modulus(ctx));
200+
fmpz_randtest_unsigned(poly->coeffs + 2, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
201+
fmpz_mod(poly->coeffs + 2, poly->coeffs + 2, fmpz_mod_ctx_modulus(ctx));
202+
fmpz_randtest_unsigned(poly->coeffs + 3, state, fmpz_bits(fmpz_mod_ctx_modulus(ctx) + 1));
203+
fmpz_mod(poly->coeffs + 3, poly->coeffs + 3, fmpz_mod_ctx_modulus(ctx));
191204
fmpz_one(poly->coeffs + len - 1);
192205
_fmpz_mod_poly_set_length(poly, len);
193206
}

0 commit comments

Comments
 (0)