sortbased_rand

sortbased_rand(n_range: int, iterations: int, n_picks: int = -1)[source][source]

Generate random numbers using sort-based sampling, resulting in a random choice generation without replacement along the first axis.

Parameters:
  • n_range (int) – The range of numbers to sample from.

  • iterations (int) – The number of iterations to run.

  • n_picks (int) – The number of numbers to pick from the range. If -1, then the number of picks is equal to the range.

Returns:

An array of shape (iterations, n_picks) containing the random numbers.

Return type:

array

References

[1] stackoverflow link

Examples

>>> np.random.seed(0)
>>> sortbased_rand(10, 5, 3)
array([[9, 4, 6],
       [6, 4, 5],
       [4, 6, 9],
       [4, 0, 2],
       [3, 7, 6]])