Repository: Mathics3/mathics-core (language: python)

Issue:
RandomSample on a list returns one item. 
Again an exmple from https://www.wolfram.com/language/elementary-introduction/2nd-ed/30-rearranging-lists.html

```
RandomSample[Range[10]]
```

always produces one item when it should produce more.  A revised version of chapter 30 will go out with the next docker update (which will not be done with the 5.0.0 release but probably a week later.)



Discussion / hints:

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index dd46719bd..97401015b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -39,6 +39,7 @@ Bugs
 ++++
 
 # ``0`` with a given precision (like in ```0`3```) is now parsed as ``0``, an integer number.
+#. ``RandomSample`` with one list argument now returns a random ordering of the list items. Previously it would return just one item.
 
 
 Enhancements
diff --git a/mathics/builtin/numbers/randomnumbers.py b/mathics/builtin/numbers/randomnumbers.py
index aae92d365..115af6f00 100644
--- a/mathics/builtin/numbers/randomnumbers.py
+++ b/mathics/builtin/numbers/randomnumbers.py
@@ -735,8 +735,8 @@ class RandomSample(_RandomSelection):
     </dl>
 
     >> SeedRandom[42]
-    >> RandomSample[{a, b, c}]
-     = {a}
+    >> RandomSample[{a, b, c, d}]
+     = {b, d, a, c}
     >> SeedRandom[42]
     >> RandomSample[{a, b, c, d, e, f, g, h}, 7]
      = {b, f, a, h, c, e, d}
@@ -744,6 +744,9 @@ class RandomSample(_RandomSelection):
     >> RandomSample[{"a", {1, 2}, x, {}}, 3]
      = {{1, 2}, {}, a}
     >> SeedRandom[42]
+    >> RandomSample[Range[10]]
+     = {9, 2, 6, 1, 8, 3, 10, 5, 4, 7}
+    >> SeedRandom[42]
     >> RandomSample[Range[100], {2, 3}]
      = {{84, 54, 71}, {46, 45, 40}}
     >> SeedRandom[42]
@@ -751,6 +754,11 @@ class RandomSample(_RandomSelection):
      = {62, 98, 86, 78, 40}
     """
 
+    rules = {
+        "%(name)s[spec_]": "%(name)s[spec, {Length[spec]}]",
+        "%(name)s[spec_, n_Integer]": "%(name)s[spec, {n}]",
+    }
+
     _replace = False
     summary_text = "pick a sample at random from a list"
 


Test patch:
diff --git a/test/builtin/numbers/test_randomnumbers.py b/test/builtin/numbers/test_randomnumbers.py
new file mode 100644
index 000000000..31fdaaf00
--- /dev/null
+++ b/test/builtin/numbers/test_randomnumbers.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+"""
+Unit tests for mathics.builtins.numbers.randomnumbers
+"""
+
+import pytest
+from test.helper import check_evaluation
+
+
+@pytest.mark.parametrize(
+    ("str_expr", "str_expected"),
+    [
+        ("SeedRandom[42]; RandomSample[{a, b, c, d}]", "{b, d, a, c}"),
+        (
+            "SeedRandom[42]; RandomSample[{a, b, c, d, e, f, g, h}, 7]",
+            "{b, f, a, h, c, e, d}",
+        ),
+        ('SeedRandom[42]; RandomSample[{"a", {1, 2}, x, {}}, 3]', "{{1, 2}, {}, a}"),
+        (
+            "SeedRandom[42]; RandomSample[Range[100], {2, 3}]",
+            "{{84, 54, 71}, {46, 45, 40}}",
+        ),
+        (
+            "SeedRandom[42]; RandomSample[Range[100] -> Range[100], 5]",
+            "{62, 98, 86, 78, 40}",
+        ),
+        ("SeedRandom[42]; RandomSample[Range[10]]", "{9, 2, 6, 1, 8, 3, 10, 5, 4, 7}"),
+        (
+            "SeedRandom[42]; RandomSample[Range[10], {10}]",
+            "{9, 2, 6, 1, 8, 3, 10, 5, 4, 7}",
+        ),
+    ],
+)
+def test_random_sample(str_expr, str_expected):
+    check_evaluation(
+        str_expr,
+        str_expected,
+        to_string_expr=True,
+        to_string_expected=True,
+    )