### Proposed new feature or change: Description ========
Often you want to randomize a "direction" that doesn't have "size". This can be useful when: * You want to randomize the direction of an NPC walk developing in a 2D or 3D games, where its speed is a predefined constant. * You're developing particles simulation with all particles moving in random directions * etc. This random direction should be an `n`th dimensional unit vector which is randomize **uniformly** from the unit sphere. That means that sections of the unit sphere with equal areas should have the same chance of getting a vector from. Implementation =========== If one wants to randomize `n`th dimensional direction uniformly, one must do the following: 1. Generate `n` components of the vector using the standard normal distribution 2. Find the norm the generated vector 3. Divide the vector by its norm In simple Python code: ```python import numpy as np def sphere_uniform(n: int): vec = np.random.normal(size=n) norm = np.sqrt(np.sum(vec ** 2)) return vec / norm ``` This implementation suggestion is based on [this blog post](https://towardsdatascience.com/the-best-way-to-pick-a-unit-vector-7bd0cc54f9b). I'm not sure if there's a faster way of implementing it using C++ and Cython, but I'm confident that someone here will know. Why Implement It in Numpy? =================== I believe that random unit vectors are common enough to be a part of Numpy. Scientists, gamers and engineers use random directions all the time, and I believe there is no reason why Numpy won't provide this ability. _______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com