@@ -54,7 +54,12 @@ gr_ctx_init_random_ring_composite(gr_ctx_t ctx, flint_rand_t state)
5454 gr_ctx_init_gr_poly (ctx , base_ring );
5555 break ;
5656 case 1 :
57- gr_ctx_init_gr_mpoly (ctx , base_ring , n_randint (state , 3 ), mpoly_ordering_randtest (state ));
57+ {
58+ /* Split state-mutating calls so consumption order is architecture-independent. */
59+ slong nvars = n_randint (state , 3 );
60+ ordering_t ord = mpoly_ordering_randtest (state );
61+ gr_ctx_init_gr_mpoly (ctx , base_ring , nvars , ord );
62+ }
5863 break ;
5964 case 2 :
6065 gr_series_ctx_init (ctx , base_ring , n_randint (state , 6 ));
@@ -127,16 +132,30 @@ gr_ctx_init_random_ring_finite_field(gr_ctx_t ctx, flint_rand_t state)
127132 switch (n_randint (state , 3 ))
128133 {
129134 case 0 :
130- gr_ctx_init_fq_nmod (ctx , n_randtest_prime (state , 0 ), 1 + n_randint (state , 4 ), NULL );
135+ {
136+ /* Split state-mutating calls so consumption order is architecture-independent. */
137+ ulong p = n_randtest_prime (state , 0 );
138+ slong d = 1 + n_randint (state , 4 );
139+ gr_ctx_init_fq_nmod (ctx , p , d , NULL );
140+ }
131141 break ;
132142
133143 case 1 :
134- gr_ctx_init_fq_zech (ctx , n_randprime (state , 4 , 0 ), 1 + n_randint (state , 3 ), NULL );
144+ {
145+ ulong p = n_randprime (state , 4 , 0 );
146+ slong d = 1 + n_randint (state , 3 );
147+ gr_ctx_init_fq_zech (ctx , p , d , NULL );
148+ }
135149 break ;
136150
137151 case 2 :
138- fmpz_randprime (t , state , 2 + n_randint (state , 100 ), 0 );
139- gr_ctx_init_fq (ctx , t , 1 + n_randint (state , 4 ), NULL );
152+ {
153+ flint_bitcnt_t bits = 2 + n_randint (state , 100 );
154+ slong d ;
155+ fmpz_randprime (t , state , bits , 0 );
156+ d = 1 + n_randint (state , 4 );
157+ gr_ctx_init_fq (ctx , t , d , NULL );
158+ }
140159 break ;
141160 }
142161
@@ -154,7 +173,16 @@ gr_ctx_init_random_ring_number_field(gr_ctx_t ctx, flint_rand_t state)
154173
155174 do
156175 {
157- fmpz_poly_randtest_irreducible (g , state , 2 + n_randint (state , 5 ), 1 + n_randint (state , 10 ));
176+ slong len ;
177+ flint_bitcnt_t bits ;
178+
179+ /* The two n_randint calls below have side effects on `state`; we
180+ split them into separate statements so the order of consumption
181+ is the same on every architecture (C does not specify the order
182+ in which function arguments are evaluated). */
183+ len = 2 + n_randint (state , 5 );
184+ bits = 1 + n_randint (state , 10 );
185+ fmpz_poly_randtest_irreducible (g , state , len , bits );
158186 } while (g -> length < 2 );
159187
160188 fmpq_poly_set_fmpz_poly (f , g );
@@ -217,10 +245,19 @@ gr_ctx_init_random_ring_builtin_poly(gr_ctx_t ctx, flint_rand_t state)
217245 gr_ctx_init_fmpq_poly (ctx );
218246 break ;
219247 case 2 :
220- gr_ctx_init_fmpz_mpoly (ctx , n_randint (state , 3 ), mpoly_ordering_randtest (state ));
248+ {
249+ /* Split state-mutating calls so consumption order is architecture-independent. */
250+ slong nvars = n_randint (state , 3 );
251+ ordering_t ord = mpoly_ordering_randtest (state );
252+ gr_ctx_init_fmpz_mpoly (ctx , nvars , ord );
253+ }
221254 break ;
222255 case 3 :
223- gr_ctx_init_fmpz_mpoly_q (ctx , n_randint (state , 2 ), mpoly_ordering_randtest (state ));
256+ {
257+ slong nvars = n_randint (state , 2 );
258+ ordering_t ord = mpoly_ordering_randtest (state );
259+ gr_ctx_init_fmpz_mpoly_q (ctx , nvars , ord );
260+ }
224261 break ;
225262 }
226263}
@@ -323,10 +360,19 @@ gr_ctx_init_random_mpoly(gr_ctx_t ctx, flint_rand_t state)
323360 switch (n_randint (state , 2 ))
324361 {
325362 case 0 :
326- gr_ctx_init_gr_mpoly (ctx , _gr_random_base_ring (state ), n_randint (state , 3 ), ordering );
363+ {
364+ /* Split state-mutating calls so consumption order is architecture-independent. */
365+ gr_ctx_struct * base = _gr_random_base_ring (state );
366+ slong nvars = n_randint (state , 3 );
367+ gr_ctx_init_gr_mpoly (ctx , base , nvars , ordering );
368+ }
327369 break ;
328370 case 1 :
329- gr_ctx_init_fmpz_mpoly (ctx , n_randint (state , 3 ), mpoly_ordering_randtest (state ));
371+ {
372+ slong nvars = n_randint (state , 3 );
373+ ordering_t ord = mpoly_ordering_randtest (state );
374+ gr_ctx_init_fmpz_mpoly (ctx , nvars , ord );
375+ }
330376 break ;
331377 }
332378}
0 commit comments