# HG changeset patch
# User Carl Witty <cwitty@newtonlabs.com>
# Date 1210458238 25200
# Node ID 8f61d426476ead5880c9ee8ed8b3e98788717778
# Parent 4be232624ce859ca49df556814a932b6fa5f5864
Make random finite field modulus use randstate
diff -r 4be232624ce8 -r 8f61d426476e sage/misc/randstate.pyx
|
a
|
b
|
|
| 354 | 354 | every function that wants to use it; don't cache it globally or |
| 355 | 355 | in a class. (Such caching would break \method{set_random_seed}). |
| 356 | 356 | |
| | 357 | \item[NTL] If you are calling code in the NTL library that uses |
| | 358 | random numbers, call \method{set_seed_ntl} at the beginning of your |
| | 359 | function, like this: |
| | 360 | \begin{verbatim} |
| | 361 | from sage.misc.randstate import current_randstate |
| | 362 | ... |
| | 363 | |
| | 364 | current_randstate().set_seed_ntl(False) |
| | 365 | \end{verbatim} |
| | 366 | |
| | 367 | Fetch the current \class{randstate} with \code{current_randstate()} in |
| | 368 | every function that wants to use it; don't cache it globally or |
| | 369 | in a class. (Such caching would break \method{set_random_seed}). |
| | 370 | |
| 357 | 371 | \item[libc] If you are writing code that calls the libc function |
| 358 | 372 | \code{random()}: don't! The \code{random()} function does not give |
| 359 | 373 | reproducible results across different operating systems, so we can't |
| … |
… |
|
| 374 | 388 | from sage.misc.randstate import current_randstate |
| 375 | 389 | ... |
| 376 | 390 | |
| 377 | | current_randstate().set_seed_libc() |
| | 391 | current_randstate().set_seed_libc(False) |
| 378 | 392 | \end{verbatim} |
| 379 | 393 | |
| 380 | 394 | Fetch the current \class{randstate} with \code{current_randstate()} in |
diff -r 4be232624ce8 -r 8f61d426476e sage/rings/finite_field_ntl_gf2e.pyx
|
a
|
b
|
|
| 48 | 48 | from sage.libs.pari.gen import gen |
| 49 | 49 | |
| 50 | 50 | from sage.interfaces.gap import is_GapElement |
| | 51 | |
| | 52 | from sage.misc.randstate import current_randstate |
| 51 | 53 | |
| 52 | 54 | from finite_field_ext_pari import FiniteField_ext_pari |
| 53 | 55 | from finite_field_element import FiniteField_ext_pariElement |
| … |
… |
|
| 161 | 163 | sage: k.modulus() |
| 162 | 164 | x^1024 + x^19 + x^6 + x + 1 |
| 163 | 165 | sage: k.<a> = GF(2^17, modulus='random') |
| 164 | | sage: k.modulus() # output random |
| 165 | | x^17 + x^16 + x^15 + x^14 + x^12 + x^11 + x^7 + x^5 + 1 |
| | 166 | sage: k.modulus() |
| | 167 | x^17 + x^16 + x^15 + x^10 + x^8 + x^6 + x^4 + x^3 + x^2 + x + 1 |
| 166 | 168 | """ |
| 167 | 169 | self._zero_element = self._new() |
| 168 | 170 | GF2E_conv_long((<FiniteField_ntl_gf2eElement>self._zero_element).x,0) |
| … |
… |
|
| 200 | 202 | |
| 201 | 203 | if modulus is None or modulus == "random": |
| 202 | 204 | if modulus == "random": |
| | 205 | current_randstate().set_seed_ntl(False) |
| 203 | 206 | GF2X_BuildSparseIrred(ntl_tmp, k) |
| 204 | 207 | GF2X_BuildRandomIrred(ntl_m, ntl_tmp) |
| 205 | 208 | elif ConwayPolynomials().has_polynomial(p, k): |