random ZZ, QQ or RR

41 views
Skip to first unread message

Roser Homs Pons

unread,
Jul 12, 2022, 3:37:52 PM7/12/22
to Macaulay2
Hi everyone,

I would like to understand what the function "random" is exactly doing in M2 for integers, rational and real numbers. In the case of integers, is it considering the uniform distribution within a certain range? What about the other two fields?

Thanks in advance for any help!

Best,
Roser

Doug Torrance

unread,
Jul 13, 2022, 9:34:15 AM7/13/22
to Macaulay2
"random ZZ" wraps around the GMP function "mpz_urandomm" (see https://gmplib.org/manual/Integer-Random-Numbers).  By default, it samples from the discrete uniform distribution on {0, 1, ... , 9}, but you can change this using the "Height" option, i.e., "random(ZZ, Height => n)" would give you a sample from the discrete uniform distribution on {0, 1, ... , n - 1}, or, equivalently, you can use "random n".  "random(a, b)" samples from the discrete uniform distribution on {a, ..., b}.

"random RR" wraps around the MPFR function "mpfr_urandomb" (see https://www.mpfr.org/mpfr-current/mpfr.html) and samples from the continuous uniform distribution on the unit interval [0, 1].  You can also use "random b" or "random(a, b)" to change the support to [0, b] or [a, b], respectively.

"random QQ" samples the numerator and denominator independently from the discrete uniform distribution on {1, ... , 10}.  The upper bound of the support can be changed using the "Height" option.

If you're interested in other probability distributions, check out the "Probability" package that was introduced in Macaulay 1.20.

Reply all
Reply to author
Forward
0 new messages