sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.31k stars 449 forks source link

sage.misc.prandom misses several functions added in Python 3 #32439

Open mkoeppe opened 3 years ago

mkoeppe commented 3 years ago

According to https://docs.python.org/3/library/random.html, we are missing the following random generators

As well as the classes to get generators without shared states

And the getter/setter

CC: @videlec

Component: misc

Issue created by migration from https://trac.sagemath.org/ticket/32439

videlec commented 2 years ago
comment:3
sage: import random
sage: import sage.misc.prandom
sage: sorted(name for name in set(dir(random)).difference(dir(sage.misc.prandom)) if not name.startswith('_') and callable(getattr(random, name)))
['Random',
 'SystemRandom',
 'choices',
 'getstate',
 'randbytes',
 'seed',
 'setstate',
 'triangular']
videlec commented 2 years ago

Description changed:

--- 
+++ 
@@ -1,3 +1,17 @@
-https://docs.python.org/3/library/random.html
+According to https://docs.python.org/3/library/random.html, we are missing the following random generators

-For example, there is `random.triangular` but no `sage.misc.prandom.triangular`.
+- [choices](https://docs.python.org/3/library/random.html#random.choices) (added in Python 3.6)
+- [randbytes](https://docs.python.org/3/library/random.html#random.randbytes) (added in Python 3.9)
+- [triangular](https://docs.python.org/3/library/random.html#random.triangular)
+
+As well as the classes to get generators without shared states
+
+- [Random class](https://docs.python.org/3/library/random.html#random.Random)
+- [SystemRandom class](https://docs.python.org/3/library/random.html#random.Random)
+
+And the getter/stter
+
+- [seed](https://docs.python.org/3/library/random.html#random.seed)
+- [getstate](https://docs.python.org/3/library/random.html#random.getstate)
+- [setstate](https://docs.python.org/3/library/random.html#random.setstate)
+
Sandstorm831 commented 1 year ago

Commit: 1a42056

Sandstorm831 commented 1 year ago

Branch: u/gh-Sandstorm831/32439

Sandstorm831 commented 1 year ago

New commits:

f0f4fc6minor documentation addition
7175d2fRevert "minor documentation addition"
81c4314implemented choices, randbytes and triangular functions
1a42056adding examples

I have added the functions along the examples, I wanted to know that do we have to write the complete Random class and SystemRandom class? Also getter, setter and seed have to be added in the both classes or seperately ?

mkoeppe commented 1 year ago

Removed branch from the issue description because it has been replaced by PR #34973