ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 23 Dec 2018 17:32:36 -0600Randomly generate a safe prime of given lengthhttp://ask.sagemath.org/question/44765/randomly-generate-a-safe-prime-of-given-length/ A prime p is said to be safe prime if (p-1)/2 is also a prime. Safe primes are heavily used in cryptography. In order to generate a random prime of 512 bits, I use
random_prime(2^512-1, false, 2^511)
How to randomly generate a safe prime of given length?pantherSun, 23 Dec 2018 17:32:36 -0600http://ask.sagemath.org/question/44765/Get bit representation of an elliptic curve group elementhttp://ask.sagemath.org/question/44547/get-bit-representation-of-an-elliptic-curve-group-element/ I can define an elliptic curve using
> E = EllipticCurve(GF(97), [2,3])
I can then compute a group on E using
> G = E.abelian_group()
I can then sample a random element in the group using
> R = G.random_element()
Is there a way I can get a bit string representation of this group element R? Actually, I am implementing a pseudo-random generator scheme, which finally outputs a group element on elliptic curve. I need to convert it to a bit string.pantherMon, 03 Dec 2018 04:38:55 -0600http://ask.sagemath.org/question/44547/list of random non-zero elementshttp://ask.sagemath.org/question/43657/list-of-random-non-zero-elements/I was wondering if there was a short way to generate lists of random non-zero elements of GF(q) ? What I have so far is:
L=[];
for i in range(10):
a=GF(25).random_element();
while a==0:
a=GF(25).random_element();
L.append(a);ParkerThu, 13 Sep 2018 04:14:36 -0500http://ask.sagemath.org/question/43657/Generating a random vector with elements in specified rangehttp://ask.sagemath.org/question/42168/generating-a-random-vector-with-elements-in-specified-range/ I would like to generate a random vector in which its elements are between 0 and 1 (including 0 and 1). As far as I know,
`v = random_matrix(ZZ, 1, 10)` is a way to generate a random matrix. How would I restrict the elements to the range I want?
I am trying to build a function with a probability input, and then compare the probability to each of the elements separately in the random vector.
ds22Wed, 25 Apr 2018 13:53:28 -0500http://ask.sagemath.org/question/42168/Is it possible to speed up loop iteration in Sage?http://ask.sagemath.org/question/41375/is-it-possible-to-speed-up-loop-iteration-in-sage/I have a sage code that looks like this:
uni = {}
end = (l[idx]^(e[idx] - 1)) * (l[idx] + 1) # where end in my case is about 2013265922 but can also be much larger
for count in range(0, end):
i = randint(1, 303325737249669131)
if i in uni:
uni[i] += 1
else:
uni[i] = 1
So basically, I want to create very large number of random integers in the given range, check whether the number was already in the dictionary, if yes increment its count, if not initialize it to 1. But, this takes such a long time that it doesn't finish in a reasonable time. Is there any way to speed up this kind of loops in Sage (or Python)?ninhoSat, 03 Mar 2018 05:10:30 -0600http://ask.sagemath.org/question/41375/Random element in a finitely generated grouphttp://ask.sagemath.org/question/39117/random-element-in-a-finitely-generated-group/ I would like to define a matrix group by some generators, e.g.
gens = [matrix(CDF,2, [1,0, -1,1]), matrix(CDF,2, [1,1,0,1])]; G = MatrixGroup(gens)
and then to generate random matrices from G. The command
G.random_element()
throws the error message: AttributeError: 'FinitelyGeneratedMatrixGroup_generic_with_category'
object has no attribute 'random_element' . I think the problem is due to the fact that my group is infinite, since it works fine if I replace the complex numbers by some finite field. Is there a better solution than just randomly multiplying the generators by hands? I am especially interested in time efficiency, since I need to generate many elements.LorWed, 11 Oct 2017 02:47:04 -0500http://ask.sagemath.org/question/39117/How to generate an element from laplace distributionhttp://ask.sagemath.org/question/26617/how-to-generate-an-element-from-laplace-distribution/ Hi, I am wondering how to generate a random element according to laplace distribution.
I tried the method RealDistribution(). But it failed.
According to the reference manual, laplace distribution is not supported.
http://www.sagemath.org/doc/reference/probability/sage/gsl/probability_distribution.html
In the manual, there are some examples showing how to deal with uniform distribution, Gaussian distribution, etc.
My questions are:
(1) How do I know exactly which distributions are supported by the RealDistribution() method?
(2) Is there anyway I can simply generate an element according to laplace distribution in sage?
Thank you in advance. qbyteTue, 21 Apr 2015 14:57:56 -0500http://ask.sagemath.org/question/26617/