Any ideas how to get a random number from 1 to n in SAGE?

Here's a bad way to do it:

sage: n = 10^2
sage: G = SymmetricGroup(n)
sage: G.random()(1)

which will blow up as n goes to infinity.

Here's a slightly better one:

sage: x = random()
sage: int(n*x)

At least it gives a float's worth of precision.

Should there be random_integer in addition to random_prime?


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to