From: Serge Koudoro <skab12@gmail.com>
Date: Wed, 3 Apr 2024 10:29:20 -0400
Subject: setup seed for random generator
Origin: upstream, https://github.com/dipy/dipy/pull/3128

This patch was adjusted to fix the reliability of the test only;
not to add the new, un-related tests from that PR.

--- dipy.orig/dipy/core/tests/test_sphere.py
+++ dipy/dipy/core/tests/test_sphere.py
@@ -10,6 +10,7 @@
                               unit_icosahedron, hemi_icosahedron)
 from dipy.core.geometry import cart2sphere, vector_norm
 from dipy.core.sphere_stats import random_uniform_on_sphere
+from dipy.testing.decorators import set_random_number_generator
 from dipy.utils.optpkg import optional_package
 
 delaunay, have_delaunay, _ = optional_package('scipy.spatial.Delaunay')
@@ -383,14 +384,15 @@
     nt.assert_array_less(dispersed_charges_potential, init_charges_potential)
 
 
-def test_fibonacci_sphere():
+@set_random_number_generator()
+def test_fibonacci_sphere(rng):
     # Test that the number of points is correct
-    points = fibonacci_sphere(n_points=724)
+    points = fibonacci_sphere(n_points=724, rng=rng)
     nt.assert_equal(len(points), 724)
 
     # Test randomization
-    points1 = fibonacci_sphere(n_points=100, randomize=True)
-    points2 = fibonacci_sphere(n_points=100, randomize=True)
+    points1 = fibonacci_sphere(n_points=100, randomize=True, rng=rng)
+    points2 = fibonacci_sphere(n_points=100, randomize=True, rng=rng)
     with nt.assert_raises(AssertionError):
         nt.assert_array_equal(points1, points2)
 
--- dipy.orig/dipy/core/sphere.py
+++ dipy/dipy/core/sphere.py
@@ -496,7 +496,7 @@
     return HemiSphere(xyz=charges), potential
 
 
-def fibonacci_sphere(n_points, randomize=True):
+def fibonacci_sphere(n_points, randomize=True, rng=None):
     """
     Generate points on the surface of a sphere using Fibonacci Spiral.
 
@@ -506,6 +506,8 @@
         The number of points to generate on the sphere surface.
     randomize : bool, optional
         If True, randomize the starting point on the sphere. Default is True.
+    rng : np.random.Generator, optional
+        If None creates random generator in function.
 
     Returns
     -------
@@ -520,7 +522,7 @@
 
     random_shift = 0
     if randomize:
-        random_generator = np.random.default_rng()
+        random_generator = rng or np.random.default_rng()
         random_shift = random_generator.integers(0, n_points)
 
     indices = np.arange(n_points)
