Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
added set_seed support for singular
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis committed May 24, 2015
1 parent e00f17b commit e532a6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sage/misc/randstate.pxd
Expand Up @@ -10,6 +10,8 @@ cdef class randstate:

cdef object _gp_saved_seeds

cdef object _singular_saved_seed

cpdef set_seed_libc(self, bint force)
cpdef set_seed_ntl(self, bint force)

Expand Down
35 changes: 35 additions & 0 deletions src/sage/misc/randstate.pyx
Expand Up @@ -439,6 +439,7 @@ cdef randstate _current_randstate
cdef randstate _libc_seed_randstate
cdef randstate _ntl_seed_randstate
cdef randstate _gap_seed_randstate
cdef randstate _singular_seed_randstate
cdef randstate _pari_seed_randstate
# For each gp subprocess that has been seeded, keep track of which
# randstate object was the most recent one to seed it.
Expand Down Expand Up @@ -707,6 +708,40 @@ cdef class randstate:

_gap_seed_randstate = self

def set_seed_singular(self):
r"""
Checks to see if ``self`` was the most recent :class:`randstate`
to seed the Singular random number generator. If not, seeds
the generator.
EXAMPLES::
sage: set_random_seed(0)
sage: current_randstate().set_seed_singular()
sage: singular.random(1, 100)
90
sage: singular.random(1, 100)
21
"""
global _singular_seed_randstate
if _singular_seed_randstate is not self:
from sage.interfaces.singular import singular

if self._singular_saved_seed is not None:
seed = self.singular_saved_seed
else:
import sage.rings.integer_ring as integer_ring
from sage.rings.integer_ring import ZZ
seed = ZZ.random_element(long(1)<<30)

# reset the seed in Singular
singular.eval('system("--random",%d)' % seed)

if _singular_seed_randstate is not None:
_singular_seed_randstate._singular_saved_seed = seed

_singular_seed_randstate = self

def set_seed_gp(self, gp=None):
r"""
Checks to see if ``self`` was the most recent :class:`randstate`
Expand Down

0 comments on commit e532a6c

Please sign in to comment.