Ticket #3153: GF2X_sparse_poly_fix_random.patch

File GF2X_sparse_poly_fix_random.patch, 2.8 KB (added by cwitty, 5 years ago)
  • sage/misc/randstate.pyx

    # 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  
    354354every function that wants to use it; don't cache it globally or  
    355355in a class.  (Such caching would break \method{set_random_seed}). 
    356356 
     357\item[NTL] If you are calling code in the NTL library that uses 
     358random numbers, call \method{set_seed_ntl} at the beginning of your 
     359function, like this: 
     360\begin{verbatim} 
     361from sage.misc.randstate import current_randstate 
     362... 
     363 
     364    current_randstate().set_seed_ntl(False) 
     365\end{verbatim} 
     366 
     367Fetch the current \class{randstate} with \code{current_randstate()} in  
     368every function that wants to use it; don't cache it globally or  
     369in a class.  (Such caching would break \method{set_random_seed}). 
     370 
    357371\item[libc] If you are writing code that calls the libc function 
    358372\code{random()}: don't!  The \code{random()} function does not give 
    359373reproducible results across different operating systems, so we can't  
     
    374388from sage.misc.randstate import current_randstate 
    375389... 
    376390 
    377     current_randstate().set_seed_libc() 
     391    current_randstate().set_seed_libc(False) 
    378392\end{verbatim} 
    379393 
    380394Fetch the current \class{randstate} with \code{current_randstate()} in  
  • sage/rings/finite_field_ntl_gf2e.pyx

    diff -r 4be232624ce8 -r 8f61d426476e sage/rings/finite_field_ntl_gf2e.pyx
    a b  
    4848from sage.libs.pari.gen import gen 
    4949 
    5050from sage.interfaces.gap import is_GapElement 
     51 
     52from sage.misc.randstate import current_randstate 
    5153 
    5254from finite_field_ext_pari import FiniteField_ext_pari 
    5355from finite_field_element import FiniteField_ext_pariElement 
     
    161163            sage: k.modulus() 
    162164            x^1024 + x^19 + x^6 + x + 1 
    163165            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 
    166168        """ 
    167169        self._zero_element = self._new() 
    168170        GF2E_conv_long((<FiniteField_ntl_gf2eElement>self._zero_element).x,0) 
     
    200202 
    201203        if modulus is None or modulus == "random": 
    202204            if modulus == "random": 
     205                current_randstate().set_seed_ntl(False) 
    203206                GF2X_BuildSparseIrred(ntl_tmp, k) 
    204207                GF2X_BuildRandomIrred(ntl_m, ntl_tmp) 
    205208            elif ConwayPolynomials().has_polynomial(p, k):