本文整理汇总了Python中sage.misc.prandom.randint函数的典型用法代码示例。如果您正苦于以下问题:Python randint函数的具体用法?Python randint怎么用?Python randint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: random_element
def random_element(self):
r"""
Return a random element in self.
EXAMPLES::
sage: F = FreeGroup(3)
sage: F.subset(3).random_element() # random
aBa
"""
if self._n == 0:
return self._free_group.one()
alphabet = self._free_group.alphabet().list()
D = len(alphabet)
d = D/2
from sage.misc.prandom import randint
j = randint(0,D-1)
data = [alphabet[j]]
while len(data) != self._n:
if j < d:
i = j + d
else:
i = j - d
j = randint(0,D-2)
if j >= i:
j += 1
data.append(alphabet[j])
return self(data, check=False)
开发者ID:videlec,项目名称:sage-train-track,代码行数:31,代码来源:free_group.py
示例2: random_chain_complex
def random_chain_complex(level=1):
"""
Return a random chain complex, defined by specifying a single
random matrix in a random degree, with differential of degree
either 1 or -1. The matrix is randomly sparse or dense.
:param level: measure of complexity: the larger this is, the
larger the matrix can be, and the larger its degree can be in
the chain complex.
:type level: positive integer; optional, default 1
EXAMPLES::
sage: from sage.homology.tests import random_chain_complex
sage: C = random_chain_complex()
sage: C
Chain complex with at most 2 nonzero terms over Integer Ring
sage: C.degree_of_differential() # random: either 1 or -1
1
"""
bound = 50*level
nrows = randint(0, bound)
ncols = randint(0, bound)
sparseness = bool(randint(0, 1))
mat = random_matrix(ZZ, nrows, ncols, sparse=sparseness)
dim = randint(-bound, bound)
deg = 2 * randint(0, 1) - 1 # -1 or 1
return ChainComplex({dim: mat}, degree = deg)
开发者ID:Babyll,项目名称:sage,代码行数:28,代码来源:tests.py
示例3: random_simplicial_complex
def random_simplicial_complex(level=1, p=0.5):
"""
Return a random simplicial complex.
:param level: measure of complexity: the larger this is, the more
vertices and therefore the larger the possible dimension of the
complex.
:type level: positive integer; optional, default 1
:param p: probability, passed on to ``simplicial_complexes.RandomComplex``
:type p: float between 0 and 1; optional; default 0.5
EXAMPLES::
sage: from sage.homology.tests import random_simplicial_complex
sage: X = random_simplicial_complex()
sage: X # random
Simplicial complex with vertex set (0, 1, 2, 3, 4, 5, 6, 7) and 31 facets
sage: X.dimension() < 11
True
"""
from sage.misc.prandom import randint
from sage.homology.examples import simplicial_complexes
n = randint(2, 4*level)
dim = randint(1, n)
return simplicial_complexes.RandomComplex(n, dim, p)
开发者ID:BlairArchibald,项目名称:sage,代码行数:25,代码来源:tests.py
示例4: transmit_unsafe
def transmit_unsafe(self, message):
r"""
Returns ``message`` with as many errors as ``self._number_errors`` in it, and as many erasures
as ``self._number_erasures`` in it.
If ``self._number_errors`` was passed as an tuple for the number of errors, it will
pick a random integer between the bounds of the tuple and use it as the number of errors.
It does the same with ``self._number_erasures``.
All erased positions are set to 0 in the transmitted message.
It is guaranteed that the erasures and the errors will never overlap:
the received message will always contains exactly as many errors and erasures
as expected.
This method does not check if ``message`` belongs to the input space of``self``.
INPUT:
- ``message`` -- a vector
OUTPUT:
- a couple of vectors, namely:
- the transmitted message, which is ``message`` with erroneous and erased positions
- the erasure vector, which contains ``1`` at the erased positions of the transmitted message
, 0 elsewhere.
EXAMPLES::
sage: F = GF(59)^11
sage: n_err, n_era = 2, 2
sage: Chan = channels.ErrorErasureChannel(F, n_err, n_era)
sage: msg = F((3, 14, 15, 9, 26, 53, 58, 9, 7, 9, 3))
sage: set_random_seed(10)
sage: Chan.transmit_unsafe(msg)
((31, 0, 15, 9, 38, 53, 58, 9, 0, 9, 3), (0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0))
"""
number_errors = randint(*self.number_errors())
number_erasures = randint(*self.number_erasures())
V = self.input_space()
n = V.dimension()
zero = V.base_ring().zero()
errors = sample(xrange(n), number_errors + number_erasures)
error_positions = errors[:number_errors]
erasure_positions = errors[number_errors:]
error_vector = random_error_vector(n, V.base_ring(), error_positions)
erasure_vector = random_error_vector(n , GF(2), erasure_positions)
message = message + error_vector
for i in erasure_positions:
message[i] = zero
return message, erasure_vector
开发者ID:sensen1,项目名称:sage,代码行数:56,代码来源:channel_constructions.py
示例5: random_even_arithgroup
def random_even_arithgroup(index,nu2_max=None,nu3_max=None):
r"""
Return a random even arithmetic subgroup
EXAMPLES::
sage: import sage.modular.arithgroup.tests as tests
sage: G = tests.random_even_arithgroup(30); G # random
Arithmetic subgroup of index 30
sage: G.is_even()
True
"""
from sage.groups.perm_gps.permgroup import PermutationGroup
test = False
if nu2_max is None:
nu2_max = index//5
elif nu2_max == 0:
assert index%2 == 0
if nu3_max is None:
nu3_max = index//7
elif nu3_max == 0:
assert index%3 == 0
while not test:
nu2 = prandom.randint(0,nu2_max)
nu2 = index%2 + nu2*2
nu3 = prandom.randint(0,nu3_max)
nu3 = index%3 + nu3*3
l = range(1,index+1)
prandom.shuffle(l)
S2 = []
for i in xrange(nu2):
S2.append((l[i],))
for i in xrange(nu2,index,2):
S2.append((l[i],l[i+1]))
prandom.shuffle(l)
S3 = []
for i in xrange(nu3):
S3.append((l[i],))
for i in xrange(nu3,index,3):
S3.append((l[i],l[i+1],l[i+2]))
G = PermutationGroup([S2,S3])
test = G.is_transitive()
return ArithmeticSubgroup_Permutation(S2=S2,S3=S3)
开发者ID:Etn40ff,项目名称:sage,代码行数:48,代码来源:tests.py
示例6: random_lattice
def random_lattice(): # Random Lattice
from sage.misc.prandom import randint
n = get_stats().counts()['nlattice']
n = randint(0,n-1)
C = getDBConnection()
res = C.Lattices.lat.find()[n]
return redirect(url_for(".render_lattice_webpage", label=res['label']))
开发者ID:am-github,项目名称:lmfdb,代码行数:7,代码来源:main.py
示例7: _random_element_from_unrank
def _random_element_from_unrank(self):
"""
A random element in ``self``.
``self.random_element()`` returns a random element in
``self`` with uniform probability.
This is the default implementation from the category
``EnumeratedSet()`` which uses the method ``unrank``.
EXAMPLES::
sage: C = FiniteEnumeratedSets().example()
sage: C.random_element()
1
sage: C._random_element_from_unrank()
2
TODO: implement _test_random which checks uniformness
"""
from sage.misc.prandom import randint
c = self.cardinality()
r = randint(0, c - 1)
return self.unrank(r)
开发者ID:sharmaeklavya2,项目名称:sage,代码行数:25,代码来源:finite_enumerated_sets.py
示例8: random_letter
def random_letter(self, exclude=[]):
"""
A random letter, different from the letters in ``exclude``.
INPUT:
- ``exclude`` -- (default:[]) list of letter to exclude
OUTPUT:
- return a random letter different from letter in exclude
EXAMPLES::
sage: A = AlphabetWithInverses(['a','b','c'], ['A','B','C'])
sage: A.random_letter(['a','b','c','A','C'])
'B'
"""
from sage.misc.prandom import randint
done = False
while not done:
j = randint(0, 2 * len(self) - 1)
a = self[j]
done = a not in exclude
return a
开发者ID:iampatrickreynolds,项目名称:sage-train-track,代码行数:26,代码来源:inverse_alphabet.py
示例9: random_element
def random_element(self):
"""
Return a random element of this dual group.
EXAMPLES::
sage: G = AbelianGroup([2,3,9])
sage: Gd = DualAbelianGroup(G)
sage: Gd.random_element()
X0*X1^2*X2
sage: N = 43^2-1
sage: G = AbelianGroup([N],names="a")
sage: Gd = DualAbelianGroup(G,names="A")
sage: a, = G.gens()
sage: A, = Gd.gens()
sage: x = a^(N/4); y = a^(N/3); z = a^(N/14)
sage: X = Gd.random_element(); X
A^615
sage: len([a for a in [x,y,z] if abs(X(a)-1)>10^(-8)])
2
"""
from sage.misc.prandom import randint
gens = self.gens()
g = gens[0]**0
for i in range(len(gens)):
g = g*gens[i]**(randint(1,gens[i].order()))
return g
开发者ID:bgxcpku,项目名称:sagelib,代码行数:27,代码来源:dual_abelian_group.py
示例10: random_hmf
def random_hmf(): # Random Hilbert modular form
from sage.misc.prandom import randint
n = get_stats().counts()['nforms']
n = randint(0,n-1)
C = getDBConnection()
res = C.hmfs.forms.find()[n]
return redirect(url_for(".render_hmf_webpage", field_label=res['field_label'], label=res['label']))
开发者ID:am-github,项目名称:lmfdb,代码行数:7,代码来源:hilbert_modular_form.py
示例11: random_element
def random_element(self):
r"""
Return a random parking function of size `n`.
The algorithm uses a circular parking space with `n+1`
spots. Then all `n` cars can park and there remains one empty
spot. Spots are then renumbered so that the empty spot is `0`.
The probability distribution is uniform on the set of
`(n+1)^{n-1}` parking functions of size `n`.
EXAMPLES::
sage: pf = ParkingFunctions(8)
sage: a = pf.random_element(); a # random
[5, 7, 2, 4, 2, 5, 1, 3]
sage: a in pf
True
"""
n = self.n
Zm = Zmod(n + 1)
fun = [Zm(randint(0, n)) for i in range(n)]
free = [Zm(j) for j in range(n + 1)]
for car in fun:
position = car
while not(position in free):
position += Zm.one()
free.remove(position)
return ParkingFunction([(i - free[0]).lift() for i in fun])
开发者ID:Etn40ff,项目名称:sage,代码行数:29,代码来源:parking_functions.py
示例12: random_element
def random_element(self, bound=None):
"""
Return a random element of this ring.
INPUT:
- ``bound``, a positive integer or ``None`` (the default). Is given,
return the coercion of an integer in the interval
``[-bound, bound]`` into this ring.
EXAMPLES::
sage: R = IntegerModRing(18)
sage: R.random_element()
2
We test ``bound``-option::
sage: R.random_element(2) in [R(16), R(17), R(0), R(1), R(2)]
True
"""
if not (bound is None):
return commutative_ring.CommutativeRing.random_element(self, bound)
a = random.randint(0, self.order() - 1)
return self(a)
开发者ID:sensen1,项目名称:sage,代码行数:25,代码来源:integer_mod_ring.py
示例13: _rand_der
def _rand_der(self):
"""
Produces a random derangement of `[1, 2, \ldots, n]`.
This is an
implementation of the algorithm described by Martinez et. al. in
[Martinez08]_.
EXAMPLES::
sage: D = Derangements(4)
sage: D._rand_der()
[2, 3, 4, 1]
"""
n = len(self._set)
A = list(range(1, n + 1))
mark = [x<0 for x in A]
i,u = n,n
while u >= 2:
if not(mark[i-1]):
while True:
j = randint(1,i-1)
if not(mark[j-1]):
A[i-1], A[j-1] = A[j-1], A[i-1]
break
p = random()
if p < (u-1) * self._count_der(u-2) // self._count_der(u):
mark[j-1] = True
u -= 1
u -= 1
i -= 1
return A
开发者ID:mcognetta,项目名称:sage,代码行数:32,代码来源:derangements.py
示例14: random_hmf
def random_hmf(): # Random Hilbert modular form
from sage.misc.prandom import randint
n = get_stats().counts()['nforms']
n = randint(0,n-1)
C = getDBConnection()
res = C.hmfs.forms.find()[n]
return hilbert_modular_form_by_label(res)
开发者ID:nilsskoruppa,项目名称:lmfdb,代码行数:7,代码来源:hilbert_modular_form.py
示例15: random_element
def random_element(self):
"""
Return a random element of this dual group.
EXAMPLES::
sage: G = AbelianGroup([2,3,9])
sage: Gd = G.dual_group(base_ring=CC)
sage: Gd.random_element()
X1^2
sage: N = 43^2-1
sage: G = AbelianGroup([N],names="a")
sage: Gd = G.dual_group(names="A", base_ring=CC)
sage: a, = G.gens()
sage: A, = Gd.gens()
sage: x = a^(N/4); y = a^(N/3); z = a^(N/14)
sage: X = A*Gd.random_element(); X
A^615
sage: len([a for a in [x,y,z] if abs(X(a)-1)>10^(-8)])
2
"""
from sage.misc.prandom import randint
result = self.one()
for g in self.gens():
order = g.order()
result *= g**(randint(0,order))
return result
开发者ID:Babyll,项目名称:sage,代码行数:28,代码来源:dual_abelian_group.py
示例16: RandomToleranceGraph
def RandomToleranceGraph(n):
r"""
Returns a random tolerance graph.
The random tolerance graph is built from a random tolerance representation
by using the function `ToleranceGraph`. This representation is a list
`((l_0,r_0,t_0), (l_1,r_1,t_1), ..., (l_k,r_k,t_k))` where `k = n-1` and
`I_i = (l_i,r_i)` denotes a random interval and `t_i` a random positive
value. The width of the representation is limited to n**2 * 2**n.
.. NOTE::
The vertices are named 0, 1, ..., n-1. The tolerance representation used
to create the graph is saved with the graph and can be recovered using
``get_vertex()`` or ``get_vertices()``.
INPUT:
- ``n`` -- number of vertices of the random graph.
EXAMPLE:
Every tolerance graph is perfect. Hence, the chromatic number is equal to
the clique number ::
sage: g = graphs.RandomToleranceGraph(8)
sage: g.clique_number() == g.chromatic_number()
True
TEST:
sage: g = graphs.RandomToleranceGraph(-2)
Traceback (most recent call last):
...
ValueError: The number `n` of vertices must be >= 0.
"""
from sage.misc.prandom import randint
from sage.graphs.generators.intersection import ToleranceGraph
if n<0:
raise ValueError('The number `n` of vertices must be >= 0.')
W = n**2 * 2**n
tolrep = [tuple(sorted((randint(0,W), randint(0,W)))) + (randint(0,W),) for i in range(n)]
return ToleranceGraph(tolrep)
开发者ID:NitikaAgarwal,项目名称:sage,代码行数:47,代码来源:random.py
示例17: random_curve
def random_curve():
from sage.misc.prandom import randint
n = get_stats().counts()['ncurves']
n = randint(0,n-1)
label = db_ec().find()[n]['label']
# This version leaves the word 'random' in the URL:
# return render_curve_webpage_by_label(label)
# This version uses the curve's own URL:
return redirect(url_for(".by_ec_label", label=label), 301)
开发者ID:sibilant,项目名称:lmfdb,代码行数:9,代码来源:elliptic_curve.py
示例18: random_element
def random_element(self, prec=None, total_measure_zero=False):
#RH: copied from RP's change
if prec == None:
prec = self._prec_cap
if prec == 0:
V = self.approx_module(0)
return CoeffMod_OMS_element(V([]), self, ordp=randint(1, self._prec_cap), check=False)
R = self.base_ring().integer_ring()
return self((R**prec).random_element())
开发者ID:lalitkumarj,项目名称:OMSCategory,代码行数:9,代码来源:coeffmod_OMS_space.py
示例19: __call__
def __call__(self):
"""
Return a new sample.
EXAMPLE::
sage: from sage.crypto.lwe import DiscreteGaussianSamplerRejection
sage: sampler = DiscreteGaussianSamplerRejection(12.0)
sage: sampler()
-5
"""
x = 0
y = 0
z = 0
while y >= z :
x = randint(0, self.upper_bound-1)
y = randint(0, self.max_precs-1)
z = self.rho[x]
return (2*randint(0,1)-1)*x
开发者ID:Etn40ff,项目名称:sage,代码行数:19,代码来源:lwe.py
示例20: random_braid
def random_braid(self,n=1):
"""
A random braid automorphism of ``self`` of length at most
``n``.
"""
A=self._alphabet
if n==0:
return self.identity_automorphism()
i=randint(1,len(A)-1)
j=randint(0,1)
result=self.braid_automorphism(i,j!=0)
for ii in xrange(n-1):
l=randint(0,1)
if l==j: i=randint(1,len(A)-1)
else:
k=randint(1,len(A)-2)
if j<=k: i=k+1
result=result*self.braid_automorphism(i,j)
return result
开发者ID:videlec,项目名称:sage-train-track,代码行数:19,代码来源:free_group.py
注:本文中的sage.misc.prandom.randint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论